# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
684408 | 2023-01-21T06:17:33 Z | PoonYaPat | Fireworks (APIO16_fireworks) | C++14 | 17 ms | 26580 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n,m; ll l[300001],r[300001],w[300001],Ymin[300001]; vector<int> adj[300001]; priority_queue<ll, vector<ll>, greater<ll>> rsq[300001]; priority_queue<ll> lsq[300001]; void dfs(int x) { int cnt=0; priority_queue<ll, vector<ll>, greater<ll>> temp; if (!adj[x].size()) { l[x]=w[x]; r[x]=w[x]; Ymin[x]=0; lsq[x].push(l[x]); rsq[x].push(r[x]); return; } for (auto s : adj[x]) { ++cnt; dfs(s); Ymin[x]+=Ymin[s]; if (lsq[x].size()) { if (l[s]>r[x]) Ymin[x]+=l[s]-r[x]; if (r[s]<l[x]) Ymin[x]+=l[x]-r[s]; } if (lsq[s].size()+rsq[s].size()>lsq[x].size()+temp.size()) swap(lsq[x],lsq[s]), swap(temp,rsq[s]); while (!lsq[s].empty()) { if (lsq[s].top()>=temp.top()) temp.push(lsq[s].top()); else lsq[x].push(lsq[s].top()); lsq[s].pop(); } while (!rsq[s].empty()) { if (rsq[s].top()>=temp.top()) temp.push(rsq[s].top()); else lsq[x].push(rsq[s].top()); rsq[s].pop(); } while (temp.size()>cnt) lsq[x].push(temp.top()), temp.pop(); while (temp.size()<cnt) temp.push(lsq[x].top()), lsq[x].pop(); l[x]=lsq[x].top(); r[x]=temp.top(); } l[x]=lsq[x].top()+w[x]; r[x]=temp.top()+w[x]; lsq[x].pop(); lsq[x].push(l[x]); rsq[x].push(r[x]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; for (int i=2; i<=n+m; ++i) { int u; cin>>u>>w[i]; adj[u].push_back(i); } dfs(1); cout<<Ymin[1]; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 26068 KB | Output is correct |
2 | Correct | 15 ms | 26068 KB | Output is correct |
3 | Correct | 16 ms | 26188 KB | Output is correct |
4 | Correct | 13 ms | 26080 KB | Output is correct |
5 | Correct | 13 ms | 26068 KB | Output is correct |
6 | Correct | 12 ms | 26068 KB | Output is correct |
7 | Correct | 12 ms | 26148 KB | Output is correct |
8 | Correct | 12 ms | 26136 KB | Output is correct |
9 | Correct | 12 ms | 26068 KB | Output is correct |
10 | Correct | 12 ms | 26196 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 26180 KB | Output is correct |
2 | Correct | 12 ms | 26184 KB | Output is correct |
3 | Correct | 12 ms | 26120 KB | Output is correct |
4 | Correct | 14 ms | 26068 KB | Output is correct |
5 | Correct | 13 ms | 26068 KB | Output is correct |
6 | Correct | 15 ms | 26116 KB | Output is correct |
7 | Correct | 12 ms | 26152 KB | Output is correct |
8 | Correct | 13 ms | 26100 KB | Output is correct |
9 | Correct | 13 ms | 26092 KB | Output is correct |
10 | Correct | 12 ms | 26196 KB | Output is correct |
11 | Correct | 13 ms | 26136 KB | Output is correct |
12 | Correct | 14 ms | 26196 KB | Output is correct |
13 | Correct | 13 ms | 26196 KB | Output is correct |
14 | Correct | 12 ms | 26196 KB | Output is correct |
15 | Correct | 13 ms | 26216 KB | Output is correct |
16 | Correct | 13 ms | 26216 KB | Output is correct |
17 | Correct | 12 ms | 26152 KB | Output is correct |
18 | Correct | 12 ms | 26164 KB | Output is correct |
19 | Correct | 12 ms | 26220 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 26068 KB | Output is correct |
2 | Correct | 15 ms | 26068 KB | Output is correct |
3 | Correct | 16 ms | 26188 KB | Output is correct |
4 | Correct | 13 ms | 26080 KB | Output is correct |
5 | Correct | 13 ms | 26068 KB | Output is correct |
6 | Correct | 12 ms | 26068 KB | Output is correct |
7 | Correct | 12 ms | 26148 KB | Output is correct |
8 | Correct | 12 ms | 26136 KB | Output is correct |
9 | Correct | 12 ms | 26068 KB | Output is correct |
10 | Correct | 12 ms | 26196 KB | Output is correct |
11 | Correct | 12 ms | 26180 KB | Output is correct |
12 | Correct | 12 ms | 26184 KB | Output is correct |
13 | Correct | 12 ms | 26120 KB | Output is correct |
14 | Correct | 14 ms | 26068 KB | Output is correct |
15 | Correct | 13 ms | 26068 KB | Output is correct |
16 | Correct | 15 ms | 26116 KB | Output is correct |
17 | Correct | 12 ms | 26152 KB | Output is correct |
18 | Correct | 13 ms | 26100 KB | Output is correct |
19 | Correct | 13 ms | 26092 KB | Output is correct |
20 | Correct | 12 ms | 26196 KB | Output is correct |
21 | Correct | 13 ms | 26136 KB | Output is correct |
22 | Correct | 14 ms | 26196 KB | Output is correct |
23 | Correct | 13 ms | 26196 KB | Output is correct |
24 | Correct | 12 ms | 26196 KB | Output is correct |
25 | Correct | 13 ms | 26216 KB | Output is correct |
26 | Correct | 13 ms | 26216 KB | Output is correct |
27 | Correct | 12 ms | 26152 KB | Output is correct |
28 | Correct | 12 ms | 26164 KB | Output is correct |
29 | Correct | 12 ms | 26220 KB | Output is correct |
30 | Correct | 13 ms | 26196 KB | Output is correct |
31 | Correct | 13 ms | 26256 KB | Output is correct |
32 | Correct | 13 ms | 26320 KB | Output is correct |
33 | Correct | 14 ms | 26268 KB | Output is correct |
34 | Correct | 13 ms | 26344 KB | Output is correct |
35 | Correct | 17 ms | 26440 KB | Output is correct |
36 | Correct | 16 ms | 26452 KB | Output is correct |
37 | Incorrect | 15 ms | 26580 KB | Output isn't correct |
38 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 26068 KB | Output is correct |
2 | Correct | 15 ms | 26068 KB | Output is correct |
3 | Correct | 16 ms | 26188 KB | Output is correct |
4 | Correct | 13 ms | 26080 KB | Output is correct |
5 | Correct | 13 ms | 26068 KB | Output is correct |
6 | Correct | 12 ms | 26068 KB | Output is correct |
7 | Correct | 12 ms | 26148 KB | Output is correct |
8 | Correct | 12 ms | 26136 KB | Output is correct |
9 | Correct | 12 ms | 26068 KB | Output is correct |
10 | Correct | 12 ms | 26196 KB | Output is correct |
11 | Correct | 12 ms | 26180 KB | Output is correct |
12 | Correct | 12 ms | 26184 KB | Output is correct |
13 | Correct | 12 ms | 26120 KB | Output is correct |
14 | Correct | 14 ms | 26068 KB | Output is correct |
15 | Correct | 13 ms | 26068 KB | Output is correct |
16 | Correct | 15 ms | 26116 KB | Output is correct |
17 | Correct | 12 ms | 26152 KB | Output is correct |
18 | Correct | 13 ms | 26100 KB | Output is correct |
19 | Correct | 13 ms | 26092 KB | Output is correct |
20 | Correct | 12 ms | 26196 KB | Output is correct |
21 | Correct | 13 ms | 26136 KB | Output is correct |
22 | Correct | 14 ms | 26196 KB | Output is correct |
23 | Correct | 13 ms | 26196 KB | Output is correct |
24 | Correct | 12 ms | 26196 KB | Output is correct |
25 | Correct | 13 ms | 26216 KB | Output is correct |
26 | Correct | 13 ms | 26216 KB | Output is correct |
27 | Correct | 12 ms | 26152 KB | Output is correct |
28 | Correct | 12 ms | 26164 KB | Output is correct |
29 | Correct | 12 ms | 26220 KB | Output is correct |
30 | Correct | 13 ms | 26196 KB | Output is correct |
31 | Correct | 13 ms | 26256 KB | Output is correct |
32 | Correct | 13 ms | 26320 KB | Output is correct |
33 | Correct | 14 ms | 26268 KB | Output is correct |
34 | Correct | 13 ms | 26344 KB | Output is correct |
35 | Correct | 17 ms | 26440 KB | Output is correct |
36 | Correct | 16 ms | 26452 KB | Output is correct |
37 | Incorrect | 15 ms | 26580 KB | Output isn't correct |
38 | Halted | 0 ms | 0 KB | - |