#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,i,day[100005],x[100005],node,d,w,p[100005],ans;
vector<ll> v[100005];
map<ll,ll> mp[100005];
map<ll,ll> ::iterator it;
void dfs(ll a){
map<ll,ll> ::iterator it;
for(ll i:v[a]){
dfs(i);
if(mp[a].size()<mp[i].size()) swap(mp[a],mp[i]);
for(it=mp[i].begin();it!=mp[i].end();it++){
mp[a][it->first]+=it->second;
}
}
if(day[a]>0){
mp[a][day[a]]+=x[a];
while(true){
it=mp[a].upper_bound(day[a]);
if(it==mp[a].end()) break;
if(it->second<=x[a]){
x[a]-=it->second;
mp[a].erase(it);
continue;
}
it->second-=x[a];
break;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for(i=2;i<=n;i++){
cin >> p[i];
v[p[i]].push_back(i);
}
for(i=1;i<=m;i++){
cin >> node >> d >> w;
day[node]=d;
x[node]=w;
}
dfs(1);
for(it=mp[1].begin();it!=mp[1].end();it++) ans+=it->second;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
3 ms |
8792 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
20440 KB |
Output is correct |
2 |
Correct |
31 ms |
20564 KB |
Output is correct |
3 |
Correct |
109 ms |
38988 KB |
Output is correct |
4 |
Correct |
61 ms |
21996 KB |
Output is correct |
5 |
Correct |
95 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
3 ms |
8856 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
39 ms |
27276 KB |
Output is correct |
5 |
Correct |
54 ms |
31052 KB |
Output is correct |
6 |
Correct |
57 ms |
27856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
17352 KB |
Output is correct |
2 |
Correct |
41 ms |
16464 KB |
Output is correct |
3 |
Correct |
37 ms |
20560 KB |
Output is correct |
4 |
Correct |
29 ms |
17628 KB |
Output is correct |
5 |
Correct |
37 ms |
27308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
3 ms |
8792 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
49 ms |
19544 KB |
Output is correct |
11 |
Correct |
44 ms |
18464 KB |
Output is correct |
12 |
Correct |
41 ms |
19796 KB |
Output is correct |
13 |
Correct |
29 ms |
17368 KB |
Output is correct |
14 |
Correct |
35 ms |
26964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9560 KB |
Output is correct |
2 |
Correct |
20 ms |
12288 KB |
Output is correct |
3 |
Correct |
16 ms |
12632 KB |
Output is correct |
4 |
Correct |
21 ms |
12120 KB |
Output is correct |
5 |
Correct |
7 ms |
10712 KB |
Output is correct |
6 |
Correct |
16 ms |
13916 KB |
Output is correct |
7 |
Correct |
18 ms |
17372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
3 ms |
8792 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8856 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
39 ms |
27276 KB |
Output is correct |
14 |
Correct |
54 ms |
31052 KB |
Output is correct |
15 |
Correct |
57 ms |
27856 KB |
Output is correct |
16 |
Correct |
49 ms |
19544 KB |
Output is correct |
17 |
Correct |
44 ms |
18464 KB |
Output is correct |
18 |
Correct |
41 ms |
19796 KB |
Output is correct |
19 |
Correct |
29 ms |
17368 KB |
Output is correct |
20 |
Correct |
35 ms |
26964 KB |
Output is correct |
21 |
Correct |
14 ms |
12120 KB |
Output is correct |
22 |
Correct |
53 ms |
20564 KB |
Output is correct |
23 |
Correct |
58 ms |
23716 KB |
Output is correct |
24 |
Correct |
93 ms |
32096 KB |
Output is correct |
25 |
Correct |
50 ms |
21124 KB |
Output is correct |
26 |
Correct |
69 ms |
23064 KB |
Output is correct |
27 |
Correct |
60 ms |
21864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
3 ms |
8792 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
47 ms |
20440 KB |
Output is correct |
11 |
Correct |
31 ms |
20564 KB |
Output is correct |
12 |
Correct |
109 ms |
38988 KB |
Output is correct |
13 |
Correct |
61 ms |
21996 KB |
Output is correct |
14 |
Correct |
95 ms |
23892 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
3 ms |
8856 KB |
Output is correct |
17 |
Correct |
2 ms |
8796 KB |
Output is correct |
18 |
Correct |
39 ms |
27276 KB |
Output is correct |
19 |
Correct |
54 ms |
31052 KB |
Output is correct |
20 |
Correct |
57 ms |
27856 KB |
Output is correct |
21 |
Correct |
42 ms |
17352 KB |
Output is correct |
22 |
Correct |
41 ms |
16464 KB |
Output is correct |
23 |
Correct |
37 ms |
20560 KB |
Output is correct |
24 |
Correct |
29 ms |
17628 KB |
Output is correct |
25 |
Correct |
37 ms |
27308 KB |
Output is correct |
26 |
Correct |
49 ms |
19544 KB |
Output is correct |
27 |
Correct |
44 ms |
18464 KB |
Output is correct |
28 |
Correct |
41 ms |
19796 KB |
Output is correct |
29 |
Correct |
29 ms |
17368 KB |
Output is correct |
30 |
Correct |
35 ms |
26964 KB |
Output is correct |
31 |
Correct |
5 ms |
9560 KB |
Output is correct |
32 |
Correct |
20 ms |
12288 KB |
Output is correct |
33 |
Correct |
16 ms |
12632 KB |
Output is correct |
34 |
Correct |
21 ms |
12120 KB |
Output is correct |
35 |
Correct |
7 ms |
10712 KB |
Output is correct |
36 |
Correct |
16 ms |
13916 KB |
Output is correct |
37 |
Correct |
18 ms |
17372 KB |
Output is correct |
38 |
Correct |
14 ms |
12120 KB |
Output is correct |
39 |
Correct |
53 ms |
20564 KB |
Output is correct |
40 |
Correct |
58 ms |
23716 KB |
Output is correct |
41 |
Correct |
93 ms |
32096 KB |
Output is correct |
42 |
Correct |
50 ms |
21124 KB |
Output is correct |
43 |
Correct |
69 ms |
23064 KB |
Output is correct |
44 |
Correct |
60 ms |
21864 KB |
Output is correct |
45 |
Correct |
16 ms |
12632 KB |
Output is correct |
46 |
Correct |
53 ms |
21584 KB |
Output is correct |
47 |
Correct |
79 ms |
25236 KB |
Output is correct |
48 |
Correct |
112 ms |
35136 KB |
Output is correct |
49 |
Correct |
57 ms |
22060 KB |
Output is correct |
50 |
Correct |
74 ms |
23892 KB |
Output is correct |
51 |
Correct |
64 ms |
22608 KB |
Output is correct |