# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
99947 | 2019-03-08T21:44:30 Z | TadijaSebez | Fireworks (APIO16_fireworks) | C++11 | 9 ms | 7552 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()); if(work.size()&1) { int mid=(work.size()+1)/2; sz[u]=work[mid-1]; for(ll p:work) dp[u]+=abs(sz[u]-p); } else { int mid=work.size()/2; ll a=0,b=0; for(ll p:work) a+=abs(work[mid-1]-p); for(ll p:work) b+=abs(work[mid]-p); if(a<=b) sz[u]=work[mid-1],dp[u]+=a; else sz[u]=work[mid],dp[u]+=b; } //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
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 9 ms | 7424 KB | Output is correct |
8 | Correct | 7 ms | 7396 KB | Output is correct |
9 | Correct | 9 ms | 7424 KB | Output is correct |
10 | Correct | 8 ms | 7552 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
2 | 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 | 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 | 9 ms | 7424 KB | Output is correct |
8 | Correct | 7 ms | 7396 KB | Output is correct |
9 | Correct | 9 ms | 7424 KB | Output is correct |
10 | Correct | 8 ms | 7552 KB | Output is correct |
11 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
12 | 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 | 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 | 9 ms | 7424 KB | Output is correct |
8 | Correct | 7 ms | 7396 KB | Output is correct |
9 | Correct | 9 ms | 7424 KB | Output is correct |
10 | Correct | 8 ms | 7552 KB | Output is correct |
11 | Incorrect | 8 ms | 7424 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |