link to the problem
class Solution {
public:
vector findAllPeople(int n, vector<vector>& meetings, int firstPerson) {
vectorv;
int y=meetings.size();
map<int,vector>mp;
mp[0].push_back(0);
mp[0].push_back(firstPerson);
for(int i=0;i<y;i++)
{
mp[meetings[i][2]].push_back(meetings[i][0]);
mp[meetings[i][2]].push_back(meetings[i][1]);
}
for(auto it : mp)
{
if((it.second[0]==firstPerson && it.second[1]==0) || (it.second[1]==firstPerson && it.second[0]==0))
{
v.push_back(0);
v.push_back(firstPerson);
}
else
{
if(find(v.begin(),v.end(),it.second[0])!=v.end() && find(v.begin(),v.end(),it.second[1])==v.end())
{
v.push_back(it.second[1]);
}
else if(find(v.begin(),v.end(),it.second[1])!=v.end() && find(v.begin(),v.end(),it.second[0])==v.end())
{
v.push_back(it.second[0]);
}
}
}
sort(v.begin(),v.end());
return v;
}
};
Sir,I have tried to use time variable as key,but it fails on some cases,where more than one event occur simultaneously.Please help me out with this question.
Sir how can queue help to solve this problem(as in graphs bfs).