# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110103 | 2019-05-09T13:23:48 Z | nxteru | Fireworks (APIO16_fireworks) | C++14 | 10 ms | 7424 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define F first #define S second #define PB push_back ll n,m,x[300005],y[300005],s[300005]; vector<P>g[300005]; void dfs(int v){ if(g[v].size()==0)return; vector<ll>r; for(int i=0;i<g[v].size();i++){ ll u=g[v][i].F,c=g[v][i].S; dfs(u); x[u]+=c; y[u]+=c; r.PB(x[u]); r.PB(y[u]); } sort(r.begin(),r.end()); x[v]=r[g[v].size()-1]; y[v]=r[g[v].size()]; for(int i=0;i<g[v].size();i++){ ll u=g[v][i].F; s[v]+=s[u]; if(x[v]<x[u])s[v]+=x[u]-x[v]; if(x[v]>y[u])s[v]+=x[v]-y[u]; } } int main(void){ scanf("%lld%lld",&n,&m); n+=m; for(int i=1;i<n;i++){ ll p,c; scanf("%lld%lld",&p,&c); g[--p].PB(P(i,c)); } dfs(0); printf("%lld\n",s[0]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 10 ms | 7424 KB | Output is correct |
6 | Correct | 9 ms | 7424 KB | Output is correct |
7 | Correct | 9 ms | 7424 KB | Output is correct |
8 | Correct | 10 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7424 KB | Output is correct |
2 | Correct | 10 ms | 7424 KB | Output is correct |
3 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 10 ms | 7424 KB | Output is correct |
6 | Correct | 9 ms | 7424 KB | Output is correct |
7 | Correct | 9 ms | 7424 KB | Output is correct |
8 | Correct | 10 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
11 | Correct | 9 ms | 7424 KB | Output is correct |
12 | Correct | 10 ms | 7424 KB | Output is correct |
13 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 10 ms | 7424 KB | Output is correct |
6 | Correct | 9 ms | 7424 KB | Output is correct |
7 | Correct | 9 ms | 7424 KB | Output is correct |
8 | Correct | 10 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
11 | Correct | 9 ms | 7424 KB | Output is correct |
12 | Correct | 10 ms | 7424 KB | Output is correct |
13 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |