#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 9;
ll n, m, w[100002], d[100002], k;
vector<ll>G[100002];
map<ll, ll>aib[100002];
void dfs (ll 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 (ll i = 2; i <= n; i++) {
ll x;
cin >> x;
G[x].push_back(i);
}
for (ll i = 1; i <= m; i++) {
ll v;
cin >> v;
cin >> d[v] >> w[v];
}
dfs(1);
ll ans = 0;
for (auto it : aib[1])
ans += it.second;
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
5 ms |
7252 KB |
Output is correct |
8 |
Correct |
5 ms |
7292 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
18440 KB |
Output is correct |
2 |
Correct |
38 ms |
18780 KB |
Output is correct |
3 |
Correct |
140 ms |
35848 KB |
Output is correct |
4 |
Correct |
106 ms |
19040 KB |
Output is correct |
5 |
Correct |
126 ms |
20780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
4 ms |
7508 KB |
Output is correct |
3 |
Correct |
4 ms |
7508 KB |
Output is correct |
4 |
Correct |
47 ms |
26040 KB |
Output is correct |
5 |
Correct |
66 ms |
30028 KB |
Output is correct |
6 |
Correct |
67 ms |
26160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
14472 KB |
Output is correct |
2 |
Correct |
60 ms |
13680 KB |
Output is correct |
3 |
Correct |
49 ms |
18240 KB |
Output is correct |
4 |
Correct |
36 ms |
15228 KB |
Output is correct |
5 |
Correct |
45 ms |
26096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
5 ms |
7252 KB |
Output is correct |
8 |
Correct |
5 ms |
7292 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
10 |
Correct |
74 ms |
18480 KB |
Output is correct |
11 |
Correct |
72 ms |
17156 KB |
Output is correct |
12 |
Correct |
46 ms |
18240 KB |
Output is correct |
13 |
Correct |
34 ms |
15240 KB |
Output is correct |
14 |
Correct |
43 ms |
26044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
8248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
5 ms |
7252 KB |
Output is correct |
8 |
Correct |
5 ms |
7292 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
10 |
Correct |
4 ms |
7508 KB |
Output is correct |
11 |
Correct |
4 ms |
7508 KB |
Output is correct |
12 |
Correct |
4 ms |
7508 KB |
Output is correct |
13 |
Correct |
47 ms |
26040 KB |
Output is correct |
14 |
Correct |
66 ms |
30028 KB |
Output is correct |
15 |
Correct |
67 ms |
26160 KB |
Output is correct |
16 |
Correct |
74 ms |
18480 KB |
Output is correct |
17 |
Correct |
72 ms |
17156 KB |
Output is correct |
18 |
Correct |
46 ms |
18240 KB |
Output is correct |
19 |
Correct |
34 ms |
15240 KB |
Output is correct |
20 |
Correct |
43 ms |
26044 KB |
Output is correct |
21 |
Correct |
27 ms |
11268 KB |
Output is correct |
22 |
Correct |
71 ms |
20300 KB |
Output is correct |
23 |
Correct |
87 ms |
24472 KB |
Output is correct |
24 |
Correct |
134 ms |
35592 KB |
Output is correct |
25 |
Correct |
68 ms |
18948 KB |
Output is correct |
26 |
Correct |
91 ms |
21672 KB |
Output is correct |
27 |
Correct |
96 ms |
20556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
5 ms |
7252 KB |
Output is correct |
8 |
Correct |
5 ms |
7292 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
10 |
Correct |
62 ms |
18440 KB |
Output is correct |
11 |
Correct |
38 ms |
18780 KB |
Output is correct |
12 |
Correct |
140 ms |
35848 KB |
Output is correct |
13 |
Correct |
106 ms |
19040 KB |
Output is correct |
14 |
Correct |
126 ms |
20780 KB |
Output is correct |
15 |
Correct |
4 ms |
7508 KB |
Output is correct |
16 |
Correct |
4 ms |
7508 KB |
Output is correct |
17 |
Correct |
4 ms |
7508 KB |
Output is correct |
18 |
Correct |
47 ms |
26040 KB |
Output is correct |
19 |
Correct |
66 ms |
30028 KB |
Output is correct |
20 |
Correct |
67 ms |
26160 KB |
Output is correct |
21 |
Correct |
71 ms |
14472 KB |
Output is correct |
22 |
Correct |
60 ms |
13680 KB |
Output is correct |
23 |
Correct |
49 ms |
18240 KB |
Output is correct |
24 |
Correct |
36 ms |
15228 KB |
Output is correct |
25 |
Correct |
45 ms |
26096 KB |
Output is correct |
26 |
Correct |
74 ms |
18480 KB |
Output is correct |
27 |
Correct |
72 ms |
17156 KB |
Output is correct |
28 |
Correct |
46 ms |
18240 KB |
Output is correct |
29 |
Correct |
34 ms |
15240 KB |
Output is correct |
30 |
Correct |
43 ms |
26044 KB |
Output is correct |
31 |
Incorrect |
8 ms |
8248 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |