# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
485768 | 2021-11-09T10:19:15 Z | milisav | Fireworks (APIO16_fireworks) | C++14 | 38 ms | 70792 KB |
#include<bits/stdc++.h> #define maxn 1000000 using namespace std; int n,m; vector<int> a[maxn]; int p[maxn]; int c[maxn]; long long ans; multiset<long long> x[maxn]; long long t[maxn]; int pt[maxn]; vector<long long> cur; void dfs(int u) { if(a[u].size()==0) { x[u].insert(c[u]); x[u].insert(c[u]); pt[u]=u; t[u]=c[u]; return; } for(auto v:a[u]) { dfs(v); } pt[u]=0; for(auto v:a[u]) { if(x[pt[v]].size()>x[pt[u]].size()) { pt[u]=pt[v]; } } for(auto v:a[u]) { if(pt[u]!=pt[v]) { for(auto c:x[pt[v]]) { x[pt[u]].insert(c); } } } int sz=a[u].size(); long long sum=0; for(int i=0;i<sz-1;i++) { sum+=(*x[pt[u]].rbegin()); x[pt[u]].erase(--x[pt[u]].end()); } long long p1=(*x[pt[u]].rbegin()); x[pt[u]].erase(--x[pt[u]].end()); long long p2=(*x[pt[u]].rbegin()); x[pt[u]].insert(p1+c[u]); x[pt[u]].insert(p2+c[u]); t[u]=p1+c[u]; ans+=(sum-(sz-1)*p1); for(auto v:a[u]) { ans+=(p1-t[v]); } } int main() { scanf("%d %d",&n,&m); for(int i=2;i<=n+m;i++) { scanf("%d %d",&p[i],&c[i]); a[p[i]].push_back(i); } dfs(1); printf("%lld\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 70772 KB | Output is correct |
2 | Correct | 33 ms | 70712 KB | Output is correct |
3 | Correct | 32 ms | 70652 KB | Output is correct |
4 | Correct | 32 ms | 70728 KB | Output is correct |
5 | Correct | 32 ms | 70724 KB | Output is correct |
6 | Correct | 31 ms | 70676 KB | Output is correct |
7 | Correct | 31 ms | 70732 KB | Output is correct |
8 | Correct | 32 ms | 70792 KB | Output is correct |
9 | Correct | 33 ms | 70684 KB | Output is correct |
10 | Correct | 33 ms | 70744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 70724 KB | Output is correct |
2 | Correct | 38 ms | 70756 KB | Output is correct |
3 | Incorrect | 32 ms | 70724 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 70772 KB | Output is correct |
2 | Correct | 33 ms | 70712 KB | Output is correct |
3 | Correct | 32 ms | 70652 KB | Output is correct |
4 | Correct | 32 ms | 70728 KB | Output is correct |
5 | Correct | 32 ms | 70724 KB | Output is correct |
6 | Correct | 31 ms | 70676 KB | Output is correct |
7 | Correct | 31 ms | 70732 KB | Output is correct |
8 | Correct | 32 ms | 70792 KB | Output is correct |
9 | Correct | 33 ms | 70684 KB | Output is correct |
10 | Correct | 33 ms | 70744 KB | Output is correct |
11 | Correct | 32 ms | 70724 KB | Output is correct |
12 | Correct | 38 ms | 70756 KB | Output is correct |
13 | Incorrect | 32 ms | 70724 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 70772 KB | Output is correct |
2 | Correct | 33 ms | 70712 KB | Output is correct |
3 | Correct | 32 ms | 70652 KB | Output is correct |
4 | Correct | 32 ms | 70728 KB | Output is correct |
5 | Correct | 32 ms | 70724 KB | Output is correct |
6 | Correct | 31 ms | 70676 KB | Output is correct |
7 | Correct | 31 ms | 70732 KB | Output is correct |
8 | Correct | 32 ms | 70792 KB | Output is correct |
9 | Correct | 33 ms | 70684 KB | Output is correct |
10 | Correct | 33 ms | 70744 KB | Output is correct |
11 | Correct | 32 ms | 70724 KB | Output is correct |
12 | Correct | 38 ms | 70756 KB | Output is correct |
13 | Incorrect | 32 ms | 70724 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |