/*
// Definition for Employee.
class Employee {
public:
int id;
int importance;
vector<int> subordinates;
};
*/
class Solution {
private:
unordered_map<int, Employee*> h;
int dfs(int id) {
int res = h[id]->importance;
for (int son: h[id]->subordinates) {
res += dfs(son);
}
return res;
}
public:
int getImportance(vector<Employee*> employees, int id) {
for (auto &e: employees) {
h[e->id] = e;
}
return dfs(id);
}
};