-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path0690.cpp
More file actions
32 lines (28 loc) · 693 Bytes
/
Copy path0690.cpp
File metadata and controls
32 lines (28 loc) · 693 Bytes
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
32
/*
// Definition for Employee.
class Employee {
public:
int id;
int importance;
vector<int> subordinates;
};
*/
class Solution {
public:
int getImportance(const vector<Employee *> employees, int id) const {
static const Employee *um[2001];
memset(um, 0x00, sizeof(um));
for (const Employee *employee : employees)
um[employee->id] = employee;
int res = 0;
queue<int> q({id});
while (!q.empty()) {
int id = q.front();
q.pop();
res += um[id]->importance;
for (const int sub : um[id]->subordinates)
q.push(sub);
}
return res;
}
};