/*
// Employee info
class Employee {
public:
// It's the unique ID of each node.
// unique id of this employee
int id;
// the importance value of this employee
int importance;
// the id of direct subordinates
vector<int> subordinates;
};
*/
class Solution {
private:
int getIndex(vector<Employee*> employees, int id)
{
for(int i=0;i<employees.size();i++)
if(employees[i]->id ==id)
return i;
return -1;
}
public:
int getImportance(vector<Employee*> employees, int id) {
int ind=getIndex(employees,id);
int res=employees[ind]->importance;
for(auto i: employees[ind]->subordinates)
{
int n=getIndex(employees,i);
if(employees[n]->subordinates.empty())
res+= employees[n]->importance;
else
res+=getImportance(employees,employees[n]->id);
}
return res;
}
};