# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242367 | 2020-06-27T11:36:38 Z | dantoh000 | Magic Tree (CEOI19_magictree) | C++14 | 115 ms | 37984 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n,m,k; int p[100005]; vector<int> G[100005]; int a[100005]; int L[100005]; int V[100005][20]; ll dp[100005][20]; bool isline = 1; ll LEAFANS = 0; void dfs(int u){ dp[u][0] = dp[u][1] = 0; for (auto v: G[u]){ dfs(v); for (int i = 0; i < k; i++) dp[u][i] += dp[v][i]; } for (int i = 0; i < k; i++){ dp[u][i] += V[u][i]; } for (int i = k-2; i >= 0; i--){ dp[u][i] = max(dp[u][i],dp[u][i+1]); } } int main(){ scanf("%d%d%d",&n,&m,&k); for (int i = 2; i <= n; i++){ scanf("%d",&p[i]); G[p[i]].push_back(i); if (p[i] != i-1) isline = false; } for (int i = 0; i < m; i++){ int v,d,w; scanf("%d%d%d",&v,&d,&w); a[v] = d; LEAFANS += w; if (k <= 20) V[v][k-d] += w; } if (k <= 20){ dfs(1); printf("%lld\n",dp[1][0]); } else if (isline){ int ans = 0; for (int i = 0; i <= n; i++) L[i] = 1000000005; for (int i = n; i >= 1; i--){ if (a[i] == 0) continue; int pos = upper_bound(L,L+ans,a[i])-L; //printf("%d goes %d\n",a[i],pos); L[pos] = a[i]; ans = max(ans,pos+1); } printf("%d\n",ans); } else printf("%lld\n",LEAFANS); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2688 KB | Output is correct |
4 | Correct | 6 ms | 2560 KB | Output is correct |
5 | Correct | 6 ms | 2688 KB | Output is correct |
6 | Correct | 6 ms | 2688 KB | Output is correct |
7 | Correct | 6 ms | 2688 KB | Output is correct |
8 | Correct | 6 ms | 2688 KB | Output is correct |
9 | Correct | 6 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 4864 KB | Output is correct |
2 | Correct | 35 ms | 5688 KB | Output is correct |
3 | Correct | 66 ms | 4100 KB | Output is correct |
4 | Correct | 56 ms | 3960 KB | Output is correct |
5 | Correct | 64 ms | 4216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2688 KB | Output is correct |
4 | Correct | 58 ms | 6904 KB | Output is correct |
5 | Correct | 62 ms | 6904 KB | Output is correct |
6 | Correct | 65 ms | 7032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 106 ms | 28536 KB | Output is correct |
2 | Correct | 105 ms | 28536 KB | Output is correct |
3 | Correct | 100 ms | 32632 KB | Output is correct |
4 | Correct | 75 ms | 27504 KB | Output is correct |
5 | Correct | 82 ms | 37880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2688 KB | Output is correct |
4 | Correct | 6 ms | 2560 KB | Output is correct |
5 | Correct | 6 ms | 2688 KB | Output is correct |
6 | Correct | 6 ms | 2688 KB | Output is correct |
7 | Correct | 6 ms | 2688 KB | Output is correct |
8 | Correct | 6 ms | 2688 KB | Output is correct |
9 | Correct | 6 ms | 2688 KB | Output is correct |
10 | Correct | 115 ms | 28536 KB | Output is correct |
11 | Correct | 109 ms | 28536 KB | Output is correct |
12 | Correct | 101 ms | 32632 KB | Output is correct |
13 | Correct | 75 ms | 27504 KB | Output is correct |
14 | Correct | 79 ms | 37984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 3200 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2688 KB | Output is correct |
4 | Correct | 6 ms | 2560 KB | Output is correct |
5 | Correct | 6 ms | 2688 KB | Output is correct |
6 | Correct | 6 ms | 2688 KB | Output is correct |
7 | Correct | 6 ms | 2688 KB | Output is correct |
8 | Correct | 6 ms | 2688 KB | Output is correct |
9 | Correct | 6 ms | 2688 KB | Output is correct |
10 | Correct | 6 ms | 2688 KB | Output is correct |
11 | Correct | 6 ms | 2688 KB | Output is correct |
12 | Correct | 6 ms | 2688 KB | Output is correct |
13 | Correct | 58 ms | 6904 KB | Output is correct |
14 | Correct | 62 ms | 6904 KB | Output is correct |
15 | Correct | 65 ms | 7032 KB | Output is correct |
16 | Correct | 115 ms | 28536 KB | Output is correct |
17 | Correct | 109 ms | 28536 KB | Output is correct |
18 | Correct | 101 ms | 32632 KB | Output is correct |
19 | Correct | 75 ms | 27504 KB | Output is correct |
20 | Correct | 79 ms | 37984 KB | Output is correct |
21 | Incorrect | 17 ms | 3200 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2688 KB | Output is correct |
4 | Correct | 6 ms | 2560 KB | Output is correct |
5 | Correct | 6 ms | 2688 KB | Output is correct |
6 | Correct | 6 ms | 2688 KB | Output is correct |
7 | Correct | 6 ms | 2688 KB | Output is correct |
8 | Correct | 6 ms | 2688 KB | Output is correct |
9 | Correct | 6 ms | 2688 KB | Output is correct |
10 | Correct | 41 ms | 4864 KB | Output is correct |
11 | Correct | 35 ms | 5688 KB | Output is correct |
12 | Correct | 66 ms | 4100 KB | Output is correct |
13 | Correct | 56 ms | 3960 KB | Output is correct |
14 | Correct | 64 ms | 4216 KB | Output is correct |
15 | Correct | 6 ms | 2688 KB | Output is correct |
16 | Correct | 6 ms | 2688 KB | Output is correct |
17 | Correct | 6 ms | 2688 KB | Output is correct |
18 | Correct | 58 ms | 6904 KB | Output is correct |
19 | Correct | 62 ms | 6904 KB | Output is correct |
20 | Correct | 65 ms | 7032 KB | Output is correct |
21 | Correct | 106 ms | 28536 KB | Output is correct |
22 | Correct | 105 ms | 28536 KB | Output is correct |
23 | Correct | 100 ms | 32632 KB | Output is correct |
24 | Correct | 75 ms | 27504 KB | Output is correct |
25 | Correct | 82 ms | 37880 KB | Output is correct |
26 | Correct | 115 ms | 28536 KB | Output is correct |
27 | Correct | 109 ms | 28536 KB | Output is correct |
28 | Correct | 101 ms | 32632 KB | Output is correct |
29 | Correct | 75 ms | 27504 KB | Output is correct |
30 | Correct | 79 ms | 37984 KB | Output is correct |
31 | Incorrect | 12 ms | 3200 KB | Output isn't correct |
32 | Halted | 0 ms | 0 KB | - |