# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
676541 | 2022-12-31T08:24:03 Z | numberes | Fireworks (APIO16_fireworks) | C++17 | 253 ms | 92016 KB |
/** * @date 2022-12-31 15:25:48 * @author numberes * 煮不在乎.RAmen! * https://oj.uz/problem/view/APIO16_fireworks */ #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int,int> #define ll long long using namespace std; priority_queue<ll> pq[300005]; ll a[300005],b[300005]; int n,m; vector<pii> g[300005]; void dfs(int u,int c){ if(!g[u].size()){ pq[u].push(c);pq[u].push(c); a[u]=1;b[u]=-c; return; } for(auto now:g[u]){ int v=now.fi,vc=now.se; dfs(v,vc); if(pq[u].size()<pq[v].size()) swap(pq[u],pq[v]); while(!pq[v].empty()){pq[u].push(pq[v].top());pq[v].pop();} a[u]+=a[v];b[u]+=b[v]; } while(a[u]>1){ a[u]--;b[u]+=pq[u].top(); pq[u].pop(); } int k=a[u];vector<ll> upd; while(k>=0){ upd.pb(pq[u].top()+c); pq[u].pop(); k--; } for(auto now:upd) pq[u].push(now); b[u]-=c; } int main(){ scanf("%d %d",&n,&m); for(int i=2;i<=n+m;i++){ int u,c; scanf("%d %d",&u,&c); g[u].pb(mp(i,c)); } dfs(1,0); while(a[1]>0){ a[1]--;b[1]+=pq[1].top(); pq[1].pop(); } printf("%lld\n",b[1]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 16724 KB | Output is correct |
2 | Correct | 9 ms | 16692 KB | Output is correct |
3 | Correct | 9 ms | 16700 KB | Output is correct |
4 | Correct | 9 ms | 16752 KB | Output is correct |
5 | Correct | 9 ms | 16724 KB | Output is correct |
6 | Correct | 8 ms | 16768 KB | Output is correct |
7 | Correct | 9 ms | 16756 KB | Output is correct |
8 | Correct | 10 ms | 16748 KB | Output is correct |
9 | Correct | 9 ms | 16756 KB | Output is correct |
10 | Correct | 9 ms | 16724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 16724 KB | Output is correct |
2 | Correct | 8 ms | 16724 KB | Output is correct |
3 | Correct | 8 ms | 16748 KB | Output is correct |
4 | Correct | 10 ms | 16748 KB | Output is correct |
5 | Correct | 11 ms | 16724 KB | Output is correct |
6 | Correct | 9 ms | 16724 KB | Output is correct |
7 | Correct | 9 ms | 16724 KB | Output is correct |
8 | Correct | 9 ms | 16724 KB | Output is correct |
9 | Correct | 9 ms | 16680 KB | Output is correct |
10 | Correct | 8 ms | 16752 KB | Output is correct |
11 | Correct | 8 ms | 16724 KB | Output is correct |
12 | Correct | 9 ms | 16724 KB | Output is correct |
13 | Correct | 9 ms | 16708 KB | Output is correct |
14 | Correct | 9 ms | 16724 KB | Output is correct |
15 | Correct | 11 ms | 16724 KB | Output is correct |
16 | Correct | 10 ms | 16852 KB | Output is correct |
17 | Correct | 11 ms | 16756 KB | Output is correct |
18 | Correct | 11 ms | 16700 KB | Output is correct |
19 | Correct | 9 ms | 16716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 16724 KB | Output is correct |
2 | Correct | 9 ms | 16692 KB | Output is correct |
3 | Correct | 9 ms | 16700 KB | Output is correct |
4 | Correct | 9 ms | 16752 KB | Output is correct |
5 | Correct | 9 ms | 16724 KB | Output is correct |
6 | Correct | 8 ms | 16768 KB | Output is correct |
7 | Correct | 9 ms | 16756 KB | Output is correct |
8 | Correct | 10 ms | 16748 KB | Output is correct |
9 | Correct | 9 ms | 16756 KB | Output is correct |
10 | Correct | 9 ms | 16724 KB | Output is correct |
11 | Correct | 9 ms | 16724 KB | Output is correct |
12 | Correct | 8 ms | 16724 KB | Output is correct |
13 | Correct | 8 ms | 16748 KB | Output is correct |
14 | Correct | 10 ms | 16748 KB | Output is correct |
15 | Correct | 11 ms | 16724 KB | Output is correct |
16 | Correct | 9 ms | 16724 KB | Output is correct |
17 | Correct | 9 ms | 16724 KB | Output is correct |
18 | Correct | 9 ms | 16724 KB | Output is correct |
19 | Correct | 9 ms | 16680 KB | Output is correct |
20 | Correct | 8 ms | 16752 KB | Output is correct |
21 | Correct | 8 ms | 16724 KB | Output is correct |
22 | Correct | 9 ms | 16724 KB | Output is correct |
23 | Correct | 9 ms | 16708 KB | Output is correct |
24 | Correct | 9 ms | 16724 KB | Output is correct |
25 | Correct | 11 ms | 16724 KB | Output is correct |
26 | Correct | 10 ms | 16852 KB | Output is correct |
27 | Correct | 11 ms | 16756 KB | Output is correct |
28 | Correct | 11 ms | 16700 KB | Output is correct |
29 | Correct | 9 ms | 16716 KB | Output is correct |
30 | Correct | 9 ms | 16724 KB | Output is correct |
31 | Correct | 9 ms | 16852 KB | Output is correct |
32 | Correct | 9 ms | 16852 KB | Output is correct |
33 | Correct | 9 ms | 16852 KB | Output is correct |
34 | Correct | 10 ms | 16980 KB | Output is correct |
35 | Correct | 11 ms | 17020 KB | Output is correct |
36 | Correct | 11 ms | 17020 KB | Output is correct |
37 | Correct | 13 ms | 17108 KB | Output is correct |
38 | Correct | 12 ms | 17108 KB | Output is correct |
39 | Correct | 11 ms | 17076 KB | Output is correct |
40 | Correct | 12 ms | 17876 KB | Output is correct |
41 | Correct | 11 ms | 17908 KB | Output is correct |
42 | Correct | 11 ms | 16980 KB | Output is correct |
43 | Correct | 11 ms | 17492 KB | Output is correct |
44 | Correct | 11 ms | 17332 KB | Output is correct |
45 | Correct | 13 ms | 17360 KB | Output is correct |
46 | Correct | 11 ms | 17236 KB | Output is correct |
47 | Correct | 11 ms | 17136 KB | Output is correct |
48 | Correct | 11 ms | 17108 KB | Output is correct |
49 | Correct | 11 ms | 17144 KB | Output is correct |
50 | Correct | 12 ms | 17108 KB | Output is correct |
51 | Correct | 10 ms | 16980 KB | Output is correct |
52 | Correct | 12 ms | 17100 KB | Output is correct |
53 | Correct | 11 ms | 17164 KB | Output is correct |
54 | Correct | 11 ms | 17136 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 16724 KB | Output is correct |
2 | Correct | 9 ms | 16692 KB | Output is correct |
3 | Correct | 9 ms | 16700 KB | Output is correct |
4 | Correct | 9 ms | 16752 KB | Output is correct |
5 | Correct | 9 ms | 16724 KB | Output is correct |
6 | Correct | 8 ms | 16768 KB | Output is correct |
7 | Correct | 9 ms | 16756 KB | Output is correct |
8 | Correct | 10 ms | 16748 KB | Output is correct |
9 | Correct | 9 ms | 16756 KB | Output is correct |
10 | Correct | 9 ms | 16724 KB | Output is correct |
11 | Correct | 9 ms | 16724 KB | Output is correct |
12 | Correct | 8 ms | 16724 KB | Output is correct |
13 | Correct | 8 ms | 16748 KB | Output is correct |
14 | Correct | 10 ms | 16748 KB | Output is correct |
15 | Correct | 11 ms | 16724 KB | Output is correct |
16 | Correct | 9 ms | 16724 KB | Output is correct |
17 | Correct | 9 ms | 16724 KB | Output is correct |
18 | Correct | 9 ms | 16724 KB | Output is correct |
19 | Correct | 9 ms | 16680 KB | Output is correct |
20 | Correct | 8 ms | 16752 KB | Output is correct |
21 | Correct | 8 ms | 16724 KB | Output is correct |
22 | Correct | 9 ms | 16724 KB | Output is correct |
23 | Correct | 9 ms | 16708 KB | Output is correct |
24 | Correct | 9 ms | 16724 KB | Output is correct |
25 | Correct | 11 ms | 16724 KB | Output is correct |
26 | Correct | 10 ms | 16852 KB | Output is correct |
27 | Correct | 11 ms | 16756 KB | Output is correct |
28 | Correct | 11 ms | 16700 KB | Output is correct |
29 | Correct | 9 ms | 16716 KB | Output is correct |
30 | Correct | 9 ms | 16724 KB | Output is correct |
31 | Correct | 9 ms | 16852 KB | Output is correct |
32 | Correct | 9 ms | 16852 KB | Output is correct |
33 | Correct | 9 ms | 16852 KB | Output is correct |
34 | Correct | 10 ms | 16980 KB | Output is correct |
35 | Correct | 11 ms | 17020 KB | Output is correct |
36 | Correct | 11 ms | 17020 KB | Output is correct |
37 | Correct | 13 ms | 17108 KB | Output is correct |
38 | Correct | 12 ms | 17108 KB | Output is correct |
39 | Correct | 11 ms | 17076 KB | Output is correct |
40 | Correct | 12 ms | 17876 KB | Output is correct |
41 | Correct | 11 ms | 17908 KB | Output is correct |
42 | Correct | 11 ms | 16980 KB | Output is correct |
43 | Correct | 11 ms | 17492 KB | Output is correct |
44 | Correct | 11 ms | 17332 KB | Output is correct |
45 | Correct | 13 ms | 17360 KB | Output is correct |
46 | Correct | 11 ms | 17236 KB | Output is correct |
47 | Correct | 11 ms | 17136 KB | Output is correct |
48 | Correct | 11 ms | 17108 KB | Output is correct |
49 | Correct | 11 ms | 17144 KB | Output is correct |
50 | Correct | 12 ms | 17108 KB | Output is correct |
51 | Correct | 10 ms | 16980 KB | Output is correct |
52 | Correct | 12 ms | 17100 KB | Output is correct |
53 | Correct | 11 ms | 17164 KB | Output is correct |
54 | Correct | 11 ms | 17136 KB | Output is correct |
55 | Correct | 16 ms | 17748 KB | Output is correct |
56 | Correct | 42 ms | 20712 KB | Output is correct |
57 | Correct | 83 ms | 23508 KB | Output is correct |
58 | Correct | 88 ms | 25288 KB | Output is correct |
59 | Correct | 119 ms | 28060 KB | Output is correct |
60 | Correct | 153 ms | 30860 KB | Output is correct |
61 | Correct | 175 ms | 33240 KB | Output is correct |
62 | Correct | 205 ms | 34852 KB | Output is correct |
63 | Correct | 243 ms | 38252 KB | Output is correct |
64 | Correct | 253 ms | 39236 KB | Output is correct |
65 | Correct | 135 ms | 91948 KB | Output is correct |
66 | Correct | 133 ms | 92016 KB | Output is correct |
67 | Correct | 132 ms | 35776 KB | Output is correct |
68 | Correct | 173 ms | 64844 KB | Output is correct |
69 | Correct | 201 ms | 60696 KB | Output is correct |
70 | Correct | 196 ms | 60632 KB | Output is correct |
71 | Correct | 188 ms | 49732 KB | Output is correct |
72 | Correct | 175 ms | 49916 KB | Output is correct |
73 | Correct | 151 ms | 46156 KB | Output is correct |
74 | Correct | 165 ms | 46408 KB | Output is correct |
75 | Correct | 159 ms | 44812 KB | Output is correct |
76 | Correct | 162 ms | 44924 KB | Output is correct |
77 | Correct | 160 ms | 44220 KB | Output is correct |
78 | Correct | 159 ms | 42524 KB | Output is correct |
79 | Correct | 148 ms | 43056 KB | Output is correct |