# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
922884 | 2024-02-06T08:48:29 Z | ttamx | Magic Tree (CEOI19_magictree) | C++14 | 97 ms | 32848 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N=1e5+5; int n,m,k; vector<int> adj[N]; int d[N],w[N]; map<int,ll> dp[N]; void dfs(int u){ for(auto v:adj[u]){ dfs(v); if(dp[v].size()>dp[u].size())swap(dp[u],dp[v]); for(auto [x,y]:dp[v])dp[u][x]+=y; dp[v].clear(); } if(w[u]){ dp[u][d[u]]+=w[u]; int tmp=w[u]; for(auto it=next(dp[u].find(d[u]));it!=dp[u].end();){ if(tmp>=it->second){ tmp-=it->second; it=dp[u].erase(it); }else{ it->second-=tmp; break; } } } } int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> m >> k; for(int i=2;i<=n;i++){ int p; cin >> p; adj[p].emplace_back(i); } for(int i=1;i<=m;i++){ int u; cin >> u >> d[u] >> w[u]; } dfs(1); ll ans=0; for(auto [x,y]:dp[1])ans+=y; cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8024 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8028 KB | Output is correct |
4 | Correct | 2 ms | 8284 KB | Output is correct |
5 | Correct | 2 ms | 8284 KB | Output is correct |
6 | Correct | 3 ms | 8284 KB | Output is correct |
7 | Correct | 3 ms | 8284 KB | Output is correct |
8 | Correct | 2 ms | 8284 KB | Output is correct |
9 | Correct | 2 ms | 8284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 12580 KB | Output is correct |
2 | Correct | 33 ms | 19536 KB | Output is correct |
3 | Correct | 97 ms | 15900 KB | Output is correct |
4 | Correct | 49 ms | 14328 KB | Output is correct |
5 | Correct | 61 ms | 16468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8280 KB | Output is correct |
2 | Correct | 3 ms | 8284 KB | Output is correct |
3 | Correct | 3 ms | 8284 KB | Output is correct |
4 | Correct | 48 ms | 28788 KB | Output is correct |
5 | Correct | 79 ms | 32848 KB | Output is correct |
6 | Correct | 64 ms | 29008 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 11996 KB | Output is correct |
2 | Correct | 55 ms | 12372 KB | Output is correct |
3 | Correct | 41 ms | 19024 KB | Output is correct |
4 | Correct | 32 ms | 10352 KB | Output is correct |
5 | Correct | 38 ms | 29008 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8024 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8028 KB | Output is correct |
4 | Correct | 2 ms | 8284 KB | Output is correct |
5 | Correct | 2 ms | 8284 KB | Output is correct |
6 | Correct | 3 ms | 8284 KB | Output is correct |
7 | Correct | 3 ms | 8284 KB | Output is correct |
8 | Correct | 2 ms | 8284 KB | Output is correct |
9 | Correct | 2 ms | 8284 KB | Output is correct |
10 | Correct | 66 ms | 11356 KB | Output is correct |
11 | Correct | 65 ms | 11328 KB | Output is correct |
12 | Correct | 38 ms | 18512 KB | Output is correct |
13 | Correct | 25 ms | 9688 KB | Output is correct |
14 | Correct | 39 ms | 28500 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 8540 KB | Output is correct |
2 | Correct | 16 ms | 10332 KB | Output is correct |
3 | Correct | 17 ms | 10332 KB | Output is correct |
4 | Correct | 17 ms | 10332 KB | Output is correct |
5 | Correct | 7 ms | 8928 KB | Output is correct |
6 | Correct | 18 ms | 13404 KB | Output is correct |
7 | Correct | 22 ms | 17632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8024 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8028 KB | Output is correct |
4 | Correct | 2 ms | 8284 KB | Output is correct |
5 | Correct | 2 ms | 8284 KB | Output is correct |
6 | Correct | 3 ms | 8284 KB | Output is correct |
7 | Correct | 3 ms | 8284 KB | Output is correct |
8 | Correct | 2 ms | 8284 KB | Output is correct |
9 | Correct | 2 ms | 8284 KB | Output is correct |
10 | Correct | 3 ms | 8280 KB | Output is correct |
11 | Correct | 3 ms | 8284 KB | Output is correct |
12 | Correct | 3 ms | 8284 KB | Output is correct |
13 | Correct | 48 ms | 28788 KB | Output is correct |
14 | Correct | 79 ms | 32848 KB | Output is correct |
15 | Correct | 64 ms | 29008 KB | Output is correct |
16 | Correct | 66 ms | 11356 KB | Output is correct |
17 | Correct | 65 ms | 11328 KB | Output is correct |
18 | Correct | 38 ms | 18512 KB | Output is correct |
19 | Correct | 25 ms | 9688 KB | Output is correct |
20 | Correct | 39 ms | 28500 KB | Output is correct |
21 | Correct | 13 ms | 9048 KB | Output is correct |
22 | Correct | 40 ms | 11356 KB | Output is correct |
23 | Correct | 61 ms | 13140 KB | Output is correct |
24 | Correct | 86 ms | 14992 KB | Output is correct |
25 | Correct | 53 ms | 13640 KB | Output is correct |
26 | Correct | 63 ms | 18444 KB | Output is correct |
27 | Correct | 60 ms | 20304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8024 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8028 KB | Output is correct |
4 | Correct | 2 ms | 8284 KB | Output is correct |
5 | Correct | 2 ms | 8284 KB | Output is correct |
6 | Correct | 3 ms | 8284 KB | Output is correct |
7 | Correct | 3 ms | 8284 KB | Output is correct |
8 | Correct | 2 ms | 8284 KB | Output is correct |
9 | Correct | 2 ms | 8284 KB | Output is correct |
10 | Correct | 42 ms | 12580 KB | Output is correct |
11 | Correct | 33 ms | 19536 KB | Output is correct |
12 | Correct | 97 ms | 15900 KB | Output is correct |
13 | Correct | 49 ms | 14328 KB | Output is correct |
14 | Correct | 61 ms | 16468 KB | Output is correct |
15 | Correct | 3 ms | 8280 KB | Output is correct |
16 | Correct | 3 ms | 8284 KB | Output is correct |
17 | Correct | 3 ms | 8284 KB | Output is correct |
18 | Correct | 48 ms | 28788 KB | Output is correct |
19 | Correct | 79 ms | 32848 KB | Output is correct |
20 | Correct | 64 ms | 29008 KB | Output is correct |
21 | Correct | 45 ms | 11996 KB | Output is correct |
22 | Correct | 55 ms | 12372 KB | Output is correct |
23 | Correct | 41 ms | 19024 KB | Output is correct |
24 | Correct | 32 ms | 10352 KB | Output is correct |
25 | Correct | 38 ms | 29008 KB | Output is correct |
26 | Correct | 66 ms | 11356 KB | Output is correct |
27 | Correct | 65 ms | 11328 KB | Output is correct |
28 | Correct | 38 ms | 18512 KB | Output is correct |
29 | Correct | 25 ms | 9688 KB | Output is correct |
30 | Correct | 39 ms | 28500 KB | Output is correct |
31 | Correct | 7 ms | 8540 KB | Output is correct |
32 | Correct | 16 ms | 10332 KB | Output is correct |
33 | Correct | 17 ms | 10332 KB | Output is correct |
34 | Correct | 17 ms | 10332 KB | Output is correct |
35 | Correct | 7 ms | 8928 KB | Output is correct |
36 | Correct | 18 ms | 13404 KB | Output is correct |
37 | Correct | 22 ms | 17632 KB | Output is correct |
38 | Correct | 13 ms | 9048 KB | Output is correct |
39 | Correct | 40 ms | 11356 KB | Output is correct |
40 | Correct | 61 ms | 13140 KB | Output is correct |
41 | Correct | 86 ms | 14992 KB | Output is correct |
42 | Correct | 53 ms | 13640 KB | Output is correct |
43 | Correct | 63 ms | 18444 KB | Output is correct |
44 | Correct | 60 ms | 20304 KB | Output is correct |
45 | Correct | 15 ms | 9308 KB | Output is correct |
46 | Correct | 50 ms | 11640 KB | Output is correct |
47 | Correct | 61 ms | 13700 KB | Output is correct |
48 | Correct | 85 ms | 15956 KB | Output is correct |
49 | Correct | 50 ms | 14288 KB | Output is correct |
50 | Correct | 72 ms | 19472 KB | Output is correct |
51 | Correct | 60 ms | 21140 KB | Output is correct |