-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question68.cpp
31 lines (27 loc) · 910 Bytes
/
Question68.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
68 -> Time Needed to Inform All Employees
Solution :
class Solution {
public:
int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {
vector<int>adj[n];
for(int i=0;i<n;i++){
if(manager[i]!=-1){
adj[manager[i]].push_back(i);
}
}
queue<int>q;
int ans=0;
q.push(headID);
vector<int>distance(n,0);
while(!q.empty()){
auto front=q.front();
q.pop();
for(auto x:adj[front]){
distance[x]=distance[front]+informTime[front];
q.push(x);
ans=max(ans,distance[x]);
}
}
return ans;
}
};