Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- int ans = 0;
- public:
- int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {
- vector<vector<int>> g;
- g.resize(n);
- // Make graph.
- for(int i=0; i<n; i++)
- if(manager[i] != -1)
- g[manager[i]].push_back(i);
- // DFS traversal.
- dfs(headID, 0, g, informTime);
- return ans;
- }
- void dfs(int node, int time, vector<vector<int>> &g, vector<int> &informTime){
- ans = max(ans, time);
- for(int child: g[node])
- dfs(child, time+informTime[node], g, informTime);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement