# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242521 | 2020-06-28T02:39:56 Z | dantoh000 | Magic Tree (CEOI19_magictree) | C++14 | 182 ms | 36984 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; typedef long long ll; int n,m,k; vector<int> G[100005]; ii V[100005]; map<int,ll> dp[100005]; void dfs(int u){ auto& cur = dp[u]; for (auto v: G[u]){ dfs(v); if (dp[v].size() > cur.size()){ swap(dp[v],cur); } for (auto x : dp[v]){ cur[x.first] += x.second; } } if (V[u] == ii(0,0)) return; cur[V[u].first] += V[u].second; int bad = V[u].second; auto it = cur.find(V[u].first); it++; while (it != cur.end()){ if (it->second < bad){ bad -= it->second; it = cur.erase(it); } else{ it->second -= bad; break; } } return; } int main(){ scanf("%d%d%d",&n,&m,&k); for (int i = 2,p; i <= n; i++){ scanf("%d",&p); G[p].push_back(i); } for (int i = 0; i < m; i++){ int v,d,w; scanf("%d%d%d",&v,&d,&w); V[v] = ii(d,w); } dfs(1); ll ans = 0; for (auto x : dp[1]) ans += x.second; printf("%lld\n",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7296 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7424 KB | Output is correct |
6 | Correct | 9 ms | 7296 KB | Output is correct |
7 | Correct | 9 ms | 7472 KB | Output is correct |
8 | Correct | 9 ms | 7452 KB | Output is correct |
9 | Correct | 9 ms | 7376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 82 ms | 18424 KB | Output is correct |
2 | Correct | 71 ms | 19704 KB | Output is correct |
3 | Correct | 167 ms | 36984 KB | Output is correct |
4 | Correct | 118 ms | 19952 KB | Output is correct |
5 | Correct | 157 ms | 22008 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7552 KB | Output is correct |
2 | Correct | 9 ms | 7552 KB | Output is correct |
3 | Correct | 9 ms | 7552 KB | Output is correct |
4 | Correct | 87 ms | 27256 KB | Output is correct |
5 | Correct | 116 ms | 31292 KB | Output is correct |
6 | Correct | 100 ms | 27384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 112 ms | 15708 KB | Output is correct |
2 | Correct | 108 ms | 14816 KB | Output is correct |
3 | Correct | 84 ms | 19576 KB | Output is correct |
4 | Correct | 66 ms | 15984 KB | Output is correct |
5 | Correct | 76 ms | 27512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7296 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7424 KB | Output is correct |
6 | Correct | 9 ms | 7296 KB | Output is correct |
7 | Correct | 9 ms | 7472 KB | Output is correct |
8 | Correct | 9 ms | 7452 KB | Output is correct |
9 | Correct | 9 ms | 7376 KB | Output is correct |
10 | Correct | 112 ms | 18936 KB | Output is correct |
11 | Correct | 105 ms | 17656 KB | Output is correct |
12 | Correct | 82 ms | 18936 KB | Output is correct |
13 | Correct | 59 ms | 15344 KB | Output is correct |
14 | Correct | 70 ms | 26872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 8192 KB | Output is correct |
2 | Correct | 45 ms | 10488 KB | Output is correct |
3 | Correct | 44 ms | 10488 KB | Output is correct |
4 | Correct | 44 ms | 10488 KB | Output is correct |
5 | Correct | 21 ms | 8824 KB | Output is correct |
6 | Correct | 43 ms | 13176 KB | Output is correct |
7 | Correct | 42 ms | 16888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7296 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7424 KB | Output is correct |
6 | Correct | 9 ms | 7296 KB | Output is correct |
7 | Correct | 9 ms | 7472 KB | Output is correct |
8 | Correct | 9 ms | 7452 KB | Output is correct |
9 | Correct | 9 ms | 7376 KB | Output is correct |
10 | Correct | 9 ms | 7552 KB | Output is correct |
11 | Correct | 9 ms | 7552 KB | Output is correct |
12 | Correct | 9 ms | 7552 KB | Output is correct |
13 | Correct | 87 ms | 27256 KB | Output is correct |
14 | Correct | 116 ms | 31292 KB | Output is correct |
15 | Correct | 100 ms | 27384 KB | Output is correct |
16 | Correct | 112 ms | 18936 KB | Output is correct |
17 | Correct | 105 ms | 17656 KB | Output is correct |
18 | Correct | 82 ms | 18936 KB | Output is correct |
19 | Correct | 59 ms | 15344 KB | Output is correct |
20 | Correct | 70 ms | 26872 KB | Output is correct |
21 | Correct | 32 ms | 11512 KB | Output is correct |
22 | Correct | 109 ms | 20476 KB | Output is correct |
23 | Correct | 146 ms | 24696 KB | Output is correct |
24 | Correct | 182 ms | 36344 KB | Output is correct |
25 | Correct | 104 ms | 19312 KB | Output is correct |
26 | Correct | 138 ms | 22264 KB | Output is correct |
27 | Correct | 116 ms | 21624 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7296 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7424 KB | Output is correct |
6 | Correct | 9 ms | 7296 KB | Output is correct |
7 | Correct | 9 ms | 7472 KB | Output is correct |
8 | Correct | 9 ms | 7452 KB | Output is correct |
9 | Correct | 9 ms | 7376 KB | Output is correct |
10 | Correct | 82 ms | 18424 KB | Output is correct |
11 | Correct | 71 ms | 19704 KB | Output is correct |
12 | Correct | 167 ms | 36984 KB | Output is correct |
13 | Correct | 118 ms | 19952 KB | Output is correct |
14 | Correct | 157 ms | 22008 KB | Output is correct |
15 | Correct | 9 ms | 7552 KB | Output is correct |
16 | Correct | 9 ms | 7552 KB | Output is correct |
17 | Correct | 9 ms | 7552 KB | Output is correct |
18 | Correct | 87 ms | 27256 KB | Output is correct |
19 | Correct | 116 ms | 31292 KB | Output is correct |
20 | Correct | 100 ms | 27384 KB | Output is correct |
21 | Correct | 112 ms | 15708 KB | Output is correct |
22 | Correct | 108 ms | 14816 KB | Output is correct |
23 | Correct | 84 ms | 19576 KB | Output is correct |
24 | Correct | 66 ms | 15984 KB | Output is correct |
25 | Correct | 76 ms | 27512 KB | Output is correct |
26 | Correct | 112 ms | 18936 KB | Output is correct |
27 | Correct | 105 ms | 17656 KB | Output is correct |
28 | Correct | 82 ms | 18936 KB | Output is correct |
29 | Correct | 59 ms | 15344 KB | Output is correct |
30 | Correct | 70 ms | 26872 KB | Output is correct |
31 | Correct | 15 ms | 8192 KB | Output is correct |
32 | Correct | 45 ms | 10488 KB | Output is correct |
33 | Correct | 44 ms | 10488 KB | Output is correct |
34 | Correct | 44 ms | 10488 KB | Output is correct |
35 | Correct | 21 ms | 8824 KB | Output is correct |
36 | Correct | 43 ms | 13176 KB | Output is correct |
37 | Correct | 42 ms | 16888 KB | Output is correct |
38 | Correct | 32 ms | 11512 KB | Output is correct |
39 | Correct | 109 ms | 20476 KB | Output is correct |
40 | Correct | 146 ms | 24696 KB | Output is correct |
41 | Correct | 182 ms | 36344 KB | Output is correct |
42 | Correct | 104 ms | 19312 KB | Output is correct |
43 | Correct | 138 ms | 22264 KB | Output is correct |
44 | Correct | 116 ms | 21624 KB | Output is correct |
45 | Correct | 37 ms | 11128 KB | Output is correct |
46 | Correct | 110 ms | 19960 KB | Output is correct |
47 | Correct | 122 ms | 23416 KB | Output is correct |
48 | Correct | 181 ms | 33344 KB | Output is correct |
49 | Correct | 119 ms | 19952 KB | Output is correct |
50 | Correct | 138 ms | 22392 KB | Output is correct |
51 | Correct | 121 ms | 21752 KB | Output is correct |