# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99946 | 2019-03-08T21:39:27 Z | TadijaSebez | Fireworks (APIO16_fireworks) | C++11 | 10 ms | 7464 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int N=300050; int par[N],len[N]; ll dep[N],dp[N],sz[N]; vector<int> E[N]; void DFS(int u) { if(E[u].size()==0) return; vector<ll> work; for(int v:E[u]) { DFS(v); dp[u]+=dp[v]; work.pb(sz[v]+len[v]); } sort(work.begin(),work.end()); int mid=(work.size()+1)/2; sz[u]=work[mid-1]; for(ll p:work) dp[u]+=abs(sz[u]-p); //printf("u:%i dp:%lld sz:%lld\n",u,dp[u],sz[u]); } int main() { int n,m; scanf("%i %i",&n,&m); n+=m; for(int i=2;i<=n;i++) { scanf("%i %i",&par[i],&len[i]); dep[i]=dep[par[i]]+len[i]; E[par[i]].pb(i); } DFS(1); printf("%lld\n",dp[1]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7424 KB | Output is correct |
2 | Correct | 8 ms | 7424 KB | Output is correct |
3 | Correct | 8 ms | 7424 KB | Output is correct |
4 | Correct | 8 ms | 7424 KB | Output is correct |
5 | Correct | 8 ms | 7424 KB | Output is correct |
6 | Correct | 8 ms | 7424 KB | Output is correct |
7 | Correct | 8 ms | 7424 KB | Output is correct |
8 | Correct | 8 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 8 ms | 7464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7424 KB | Output is correct |
2 | Correct | 8 ms | 7424 KB | Output is correct |
3 | Correct | 8 ms | 7424 KB | Output is correct |
4 | Correct | 8 ms | 7424 KB | Output is correct |
5 | Correct | 8 ms | 7424 KB | Output is correct |
6 | Correct | 8 ms | 7424 KB | Output is correct |
7 | Correct | 8 ms | 7424 KB | Output is correct |
8 | Correct | 8 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 8 ms | 7464 KB | Output is correct |
11 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7424 KB | Output is correct |
2 | Correct | 8 ms | 7424 KB | Output is correct |
3 | Correct | 8 ms | 7424 KB | Output is correct |
4 | Correct | 8 ms | 7424 KB | Output is correct |
5 | Correct | 8 ms | 7424 KB | Output is correct |
6 | Correct | 8 ms | 7424 KB | Output is correct |
7 | Correct | 8 ms | 7424 KB | Output is correct |
8 | Correct | 8 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 8 ms | 7464 KB | Output is correct |
11 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |