#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 9;
int n, m, w[100002], d[100002], k;
vector<int>G[100002];
map<int, ll>aib[100002];
void dfs (int nod) {
for (auto it : G[nod]) {
dfs(it);
if (aib[nod].size() < aib[it].size())
swap(aib[nod], aib[it]);
for (auto it2 : aib[it])
aib[nod][it2.first] += it2.second;
}
if (w[nod]) {
aib[nod][d[nod]] += w[nod];
while (1) {
auto it = aib[nod].upper_bound(d[nod]);
if (it == aib[nod].end())
break;
if (it->second < w[nod])
aib[nod].erase(it);
else {
it->second -= w[nod];
break;
}
}
}
}
int main ()
{
ios_base::sync_with_stdio(false);
cin >> n >> m >> k;
for (int i = 2; i <= n; i++) {
int x;
cin >> x;
G[x].push_back(i);
}
for (int i = 1; i <= m; i++) {
int v;
cin >> v;
cin >> d[v] >> w[v];
}
dfs(1);
int ans = 0;
for (auto it : aib[1])
ans += it.second;
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7336 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
18364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7504 KB |
Output is correct |
2 |
Correct |
4 ms |
7508 KB |
Output is correct |
3 |
Correct |
4 ms |
7504 KB |
Output is correct |
4 |
Correct |
55 ms |
27208 KB |
Output is correct |
5 |
Correct |
72 ms |
31152 KB |
Output is correct |
6 |
Correct |
70 ms |
27340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
15436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7336 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
10 |
Correct |
70 ms |
18976 KB |
Output is correct |
11 |
Correct |
71 ms |
17624 KB |
Output is correct |
12 |
Correct |
48 ms |
18784 KB |
Output is correct |
13 |
Correct |
36 ms |
15288 KB |
Output is correct |
14 |
Correct |
43 ms |
26780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
8152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7336 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
10 |
Correct |
4 ms |
7504 KB |
Output is correct |
11 |
Correct |
4 ms |
7508 KB |
Output is correct |
12 |
Correct |
4 ms |
7504 KB |
Output is correct |
13 |
Correct |
55 ms |
27208 KB |
Output is correct |
14 |
Correct |
72 ms |
31152 KB |
Output is correct |
15 |
Correct |
70 ms |
27340 KB |
Output is correct |
16 |
Correct |
70 ms |
18976 KB |
Output is correct |
17 |
Correct |
71 ms |
17624 KB |
Output is correct |
18 |
Correct |
48 ms |
18784 KB |
Output is correct |
19 |
Correct |
36 ms |
15288 KB |
Output is correct |
20 |
Correct |
43 ms |
26780 KB |
Output is correct |
21 |
Correct |
20 ms |
11480 KB |
Output is correct |
22 |
Correct |
70 ms |
20372 KB |
Output is correct |
23 |
Correct |
80 ms |
24500 KB |
Output is correct |
24 |
Correct |
136 ms |
36296 KB |
Output is correct |
25 |
Correct |
69 ms |
19204 KB |
Output is correct |
26 |
Correct |
92 ms |
22348 KB |
Output is correct |
27 |
Correct |
76 ms |
21512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7336 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
10 |
Incorrect |
55 ms |
18364 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |