# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
111510 | 2019-05-15T13:44:02 Z | nxteru | Fireworks (APIO16_fireworks) | C++14 | 2000 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=1;i<n;i++){ ll p,c; scanf("%lld%lld",&p,&c); g[--p].PB(P(i,c)); } dfs(0); printf("%lld\n",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2043 ms | 16768 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2041 ms | 16768 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2043 ms | 16768 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2043 ms | 16768 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |