# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
110102 | 2019-05-09T13:17:21 Z | nxteru | Fireworks (APIO16_fireworks) | C++14 | 11 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; P x[300005],y[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].F+=c; y[u].F+=c; r.PB(x[u].F); r.PB(y[u].F); } sort(r.begin(),r.end()); x[v].F=r[g[v].size()-1]; y[v].F=r[g[v].size()]; for(int i=0;i<g[v].size();i++){ ll u=g[v][i].F,c=x[u].S; x[v].S+=c; y[v].S+=c; if(x[v].F<x[u].F)x[v].S+=x[u].F-x[v].F; if(x[v].F>y[u].F)x[v].S+=x[v].F-y[u].F; if(y[v].F<x[u].F)y[v].S+=x[u].F-y[v].F; if(y[v].F>y[u].F)y[v].S+=y[v].F-y[u].F; } } 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",x[0].S); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 8 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 10 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 | 9 ms | 7424 KB | Output is correct |
9 | Correct | 9 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 7396 KB | Output is correct |
2 | Correct | 9 ms | 7424 KB | Output is correct |
3 | Incorrect | 9 ms | 7424 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 8 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 10 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 | 9 ms | 7424 KB | Output is correct |
9 | Correct | 9 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
11 | Correct | 11 ms | 7396 KB | Output is correct |
12 | Correct | 9 ms | 7424 KB | Output is correct |
13 | Incorrect | 9 ms | 7424 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 8 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7424 KB | Output is correct |
4 | Correct | 10 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 | 9 ms | 7424 KB | Output is correct |
9 | Correct | 9 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
11 | Correct | 11 ms | 7396 KB | Output is correct |
12 | Correct | 9 ms | 7424 KB | Output is correct |
13 | Incorrect | 9 ms | 7424 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |