1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public: int getImportance(vector<Employee*> employees, int id) { unordered_map<int, Employee*> m; for (const auto& e : employees) m[e->id] = e; int ans = 0; queue<int> q; q.push(id); while (!q.empty()) { int curr = q.front(); q.pop(); Employee* e = m[curr]; ans += e->importance; for (int sub : e->subordinates) q.push(sub); } return ans; } };
|