# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
111515 | 2019-05-15T13:46:40 Z | nxteru | Fireworks (APIO16_fireworks) | C++14 | 18 ms | 16768 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,ans,vs[300005]; priority_queue<ll>p[300005]; vector<P>g[300005]; void up(int v,ll c){ if(p[v].size()==0){ p[v].push(c); p[v].push(c); }else{ ll x=p[v].top(); p[v].pop(); ll y=p[v].top(); p[v].pop(); p[v].push(x+c); p[v].push(y+c); } } void merge(int x,int y){ if(p[vs[x]].size()<p[vs[y]].size())swap(x,y); int py=y; y=vs[y]; x=vs[x]; vs[py]=x; if(p[y].size()==0)return; ll mi=min(p[x].top(),p[y].top()); while(!p[y].empty()){ p[x].push(p[y].top()); p[y].pop(); } p[x].pop(); ans+=p[x].top()-mi; } void dfs(int v){ if(g[v].size()==0)return; for(int i=0;i<g[v].size();i++){ ll u=g[v][i].F,c=g[v][i].S; dfs(u); up(vs[u],c); merge(v,u); } } int main(void){ scanf("%lld%lld",&n,&m); n+=m; for(int i=0;i<n;i++)vs[i]=i; for(int i=1;i<n;i++){ ll q,c; scanf("%lld%lld",&q,&c); g[--q].PB(P(i,c)); } dfs(0); printf("%lld\n",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 16768 KB | Output is correct |
2 | Incorrect | 17 ms | 16740 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 16724 KB | Output is correct |
2 | Correct | 15 ms | 16768 KB | Output is correct |
3 | Incorrect | 16 ms | 16708 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 16768 KB | Output is correct |
2 | Incorrect | 17 ms | 16740 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 16768 KB | Output is correct |
2 | Incorrect | 17 ms | 16740 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |