# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242279 | 2020-06-27T08:04:35 Z | tqbfjotld | Magic Tree (CEOI19_magictree) | C++14 | 90 ms | 12796 KB |
/* subtask 1 - brute force subtask 2 - take all subtask 3 - lds subtask 4 - dp on tree, day1-day2 */ #include <bits/stdc++.h> using namespace std; int n,m,k; int p[100005]; int d[100005]; long long w[100005]; vector<int> adjl[100005]; long long tot[100005]; long long func(int node){ long long ans = 0; for (auto x : adjl[node]){ ans += func(x); tot[node] += tot[x]; } tot[node] += d[node]==1?w[node]:-w[node]; // printf("f(%d) = %lld,%lld\n",node,ans,tot[node]); return max(ans,tot[node]); } int main(){ scanf("%d%d%d",&n,&m,&k); bool subtask3 = true; for (int x = 1; x<n; x++){ scanf("%d",&p[x]); p[x]--; if (p[x]!=x-1) subtask3 = false; adjl[p[x]].push_back(x); } long long temps=0; for (int x = 0; x<m; x++){ int a,b; long long c; scanf("%d%d%lld",&a,&b,&c); a--; d[a] = b; w[a] = c; if (w[a]!=1) subtask3 = false; if (b==2) temps+=c; } if (k<=2){ printf("%lld",func(0)+temps); } else if (subtask3){ vector<int> v; for (int x = 0; x<n; x++){ if (w[x]==0) continue; if (v.empty()) v.push_back(-d[x]); else if (-d[x]>=v[(int)v.size()-1]){ v.push_back(-d[x]); } else{ int pos = upper_bound(v.begin(),v.end(),-d[x])-v.begin(); v[pos] = -d[x]; } } printf("%d",v.size()); } else{ long long ans = 0; for (int x = 0; x<n; x++){ ans += w[x]; } printf("%lld",ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 5656 KB | Output is correct |
2 | Correct | 49 ms | 5848 KB | Output is correct |
3 | Correct | 63 ms | 4984 KB | Output is correct |
4 | Correct | 58 ms | 4728 KB | Output is correct |
5 | Correct | 73 ms | 4984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2688 KB | Output is correct |
2 | Correct | 7 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2688 KB | Output is correct |
4 | Correct | 60 ms | 7416 KB | Output is correct |
5 | Correct | 59 ms | 8060 KB | Output is correct |
6 | Correct | 65 ms | 7288 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 90 ms | 6776 KB | Output is correct |
2 | Correct | 78 ms | 6648 KB | Output is correct |
3 | Correct | 70 ms | 9464 KB | Output is correct |
4 | Correct | 55 ms | 5488 KB | Output is correct |
5 | Correct | 64 ms | 12796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 11 ms | 3456 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |