# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1085156 | 2024-09-07T15:59:21 Z | ZeroCool | Fireworks (APIO16_fireworks) | C++14 | 166 ms | 71052 KB |
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define ld long double #define ar array const int MOD = 1e9 + 7; const ll INF = 1e18; const int N = 3e5 + 20; priority_queue<int> pq[N]; int n, m, A[N]; vector<int> g[N]; void dfs(int x){ for(auto u: g[x]){ dfs(u); if(pq[u].size() > pq[x].size())swap(pq[u], pq[x]); while(pq[u].size()){ pq[x].push(pq[u].top()); pq[u].pop(); } } int l = 0, r = 0; if(x < n){ for(int i = 1;i < g[x].size();i++)pq[x].pop(); l = pq[x].top(); pq[x].pop(); r = pq[x].top(); pq[x].pop(); } pq[x].push(l + A[x]); pq[x].push(r + A[x]); } signed main() {ios_base::sync_with_stdio(false);cin.tie(0); cin>>n>>m; int ans = 0; for(int i = 1;i < n + m;i++){ int p; cin>>p>>A[i]; --p; g[p].push_back(i); ans += A[i]; } dfs(0); pq[0].pop(); while(pq[0].size()){ ans -= pq[0].top(); pq[0].pop(); } cout<<ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 16728 KB | Output is correct |
2 | Correct | 7 ms | 16732 KB | Output is correct |
3 | Correct | 7 ms | 16680 KB | Output is correct |
4 | Correct | 7 ms | 16732 KB | Output is correct |
5 | Correct | 7 ms | 16732 KB | Output is correct |
6 | Correct | 7 ms | 16752 KB | Output is correct |
7 | Correct | 7 ms | 16728 KB | Output is correct |
8 | Correct | 7 ms | 16732 KB | Output is correct |
9 | Correct | 7 ms | 16732 KB | Output is correct |
10 | Correct | 8 ms | 16732 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 16904 KB | Output is correct |
2 | Correct | 8 ms | 16728 KB | Output is correct |
3 | Correct | 7 ms | 16904 KB | Output is correct |
4 | Correct | 7 ms | 16732 KB | Output is correct |
5 | Correct | 8 ms | 16732 KB | Output is correct |
6 | Correct | 7 ms | 16732 KB | Output is correct |
7 | Correct | 7 ms | 16732 KB | Output is correct |
8 | Correct | 7 ms | 16732 KB | Output is correct |
9 | Correct | 7 ms | 16732 KB | Output is correct |
10 | Correct | 8 ms | 16732 KB | Output is correct |
11 | Correct | 7 ms | 16732 KB | Output is correct |
12 | Correct | 7 ms | 16732 KB | Output is correct |
13 | Correct | 7 ms | 16732 KB | Output is correct |
14 | Correct | 7 ms | 16732 KB | Output is correct |
15 | Correct | 8 ms | 16732 KB | Output is correct |
16 | Correct | 7 ms | 16828 KB | Output is correct |
17 | Correct | 7 ms | 16732 KB | Output is correct |
18 | Correct | 9 ms | 16772 KB | Output is correct |
19 | Correct | 7 ms | 16732 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 16728 KB | Output is correct |
2 | Correct | 7 ms | 16732 KB | Output is correct |
3 | Correct | 7 ms | 16680 KB | Output is correct |
4 | Correct | 7 ms | 16732 KB | Output is correct |
5 | Correct | 7 ms | 16732 KB | Output is correct |
6 | Correct | 7 ms | 16752 KB | Output is correct |
7 | Correct | 7 ms | 16728 KB | Output is correct |
8 | Correct | 7 ms | 16732 KB | Output is correct |
9 | Correct | 7 ms | 16732 KB | Output is correct |
10 | Correct | 8 ms | 16732 KB | Output is correct |
11 | Correct | 8 ms | 16904 KB | Output is correct |
12 | Correct | 8 ms | 16728 KB | Output is correct |
13 | Correct | 7 ms | 16904 KB | Output is correct |
14 | Correct | 7 ms | 16732 KB | Output is correct |
15 | Correct | 8 ms | 16732 KB | Output is correct |
16 | Correct | 7 ms | 16732 KB | Output is correct |
17 | Correct | 7 ms | 16732 KB | Output is correct |
18 | Correct | 7 ms | 16732 KB | Output is correct |
19 | Correct | 7 ms | 16732 KB | Output is correct |
20 | Correct | 8 ms | 16732 KB | Output is correct |
21 | Correct | 7 ms | 16732 KB | Output is correct |
22 | Correct | 7 ms | 16732 KB | Output is correct |
23 | Correct | 7 ms | 16732 KB | Output is correct |
24 | Correct | 7 ms | 16732 KB | Output is correct |
25 | Correct | 8 ms | 16732 KB | Output is correct |
26 | Correct | 7 ms | 16828 KB | Output is correct |
27 | Correct | 7 ms | 16732 KB | Output is correct |
28 | Correct | 9 ms | 16772 KB | Output is correct |
29 | Correct | 7 ms | 16732 KB | Output is correct |
30 | Correct | 7 ms | 16732 KB | Output is correct |
31 | Correct | 7 ms | 16920 KB | Output is correct |
32 | Correct | 8 ms | 16788 KB | Output is correct |
33 | Correct | 8 ms | 16988 KB | Output is correct |
34 | Correct | 8 ms | 16988 KB | Output is correct |
35 | Correct | 7 ms | 17160 KB | Output is correct |
36 | Correct | 8 ms | 16984 KB | Output is correct |
37 | Correct | 8 ms | 16984 KB | Output is correct |
38 | Correct | 12 ms | 17244 KB | Output is correct |
39 | Correct | 9 ms | 17260 KB | Output is correct |
40 | Correct | 9 ms | 17760 KB | Output is correct |
41 | Correct | 8 ms | 17756 KB | Output is correct |
42 | Correct | 8 ms | 16988 KB | Output is correct |
43 | Correct | 8 ms | 17500 KB | Output is correct |
44 | Correct | 9 ms | 17244 KB | Output is correct |
45 | Correct | 9 ms | 17420 KB | Output is correct |
46 | Correct | 9 ms | 17344 KB | Output is correct |
47 | Correct | 9 ms | 17244 KB | Output is correct |
48 | Correct | 8 ms | 17244 KB | Output is correct |
49 | Correct | 9 ms | 17104 KB | Output is correct |
50 | Correct | 9 ms | 16984 KB | Output is correct |
51 | Correct | 9 ms | 16984 KB | Output is correct |
52 | Correct | 8 ms | 17140 KB | Output is correct |
53 | Correct | 9 ms | 17116 KB | Output is correct |
54 | Correct | 9 ms | 17244 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 16728 KB | Output is correct |
2 | Correct | 7 ms | 16732 KB | Output is correct |
3 | Correct | 7 ms | 16680 KB | Output is correct |
4 | Correct | 7 ms | 16732 KB | Output is correct |
5 | Correct | 7 ms | 16732 KB | Output is correct |
6 | Correct | 7 ms | 16752 KB | Output is correct |
7 | Correct | 7 ms | 16728 KB | Output is correct |
8 | Correct | 7 ms | 16732 KB | Output is correct |
9 | Correct | 7 ms | 16732 KB | Output is correct |
10 | Correct | 8 ms | 16732 KB | Output is correct |
11 | Correct | 8 ms | 16904 KB | Output is correct |
12 | Correct | 8 ms | 16728 KB | Output is correct |
13 | Correct | 7 ms | 16904 KB | Output is correct |
14 | Correct | 7 ms | 16732 KB | Output is correct |
15 | Correct | 8 ms | 16732 KB | Output is correct |
16 | Correct | 7 ms | 16732 KB | Output is correct |
17 | Correct | 7 ms | 16732 KB | Output is correct |
18 | Correct | 7 ms | 16732 KB | Output is correct |
19 | Correct | 7 ms | 16732 KB | Output is correct |
20 | Correct | 8 ms | 16732 KB | Output is correct |
21 | Correct | 7 ms | 16732 KB | Output is correct |
22 | Correct | 7 ms | 16732 KB | Output is correct |
23 | Correct | 7 ms | 16732 KB | Output is correct |
24 | Correct | 7 ms | 16732 KB | Output is correct |
25 | Correct | 8 ms | 16732 KB | Output is correct |
26 | Correct | 7 ms | 16828 KB | Output is correct |
27 | Correct | 7 ms | 16732 KB | Output is correct |
28 | Correct | 9 ms | 16772 KB | Output is correct |
29 | Correct | 7 ms | 16732 KB | Output is correct |
30 | Correct | 7 ms | 16732 KB | Output is correct |
31 | Correct | 7 ms | 16920 KB | Output is correct |
32 | Correct | 8 ms | 16788 KB | Output is correct |
33 | Correct | 8 ms | 16988 KB | Output is correct |
34 | Correct | 8 ms | 16988 KB | Output is correct |
35 | Correct | 7 ms | 17160 KB | Output is correct |
36 | Correct | 8 ms | 16984 KB | Output is correct |
37 | Correct | 8 ms | 16984 KB | Output is correct |
38 | Correct | 12 ms | 17244 KB | Output is correct |
39 | Correct | 9 ms | 17260 KB | Output is correct |
40 | Correct | 9 ms | 17760 KB | Output is correct |
41 | Correct | 8 ms | 17756 KB | Output is correct |
42 | Correct | 8 ms | 16988 KB | Output is correct |
43 | Correct | 8 ms | 17500 KB | Output is correct |
44 | Correct | 9 ms | 17244 KB | Output is correct |
45 | Correct | 9 ms | 17420 KB | Output is correct |
46 | Correct | 9 ms | 17344 KB | Output is correct |
47 | Correct | 9 ms | 17244 KB | Output is correct |
48 | Correct | 8 ms | 17244 KB | Output is correct |
49 | Correct | 9 ms | 17104 KB | Output is correct |
50 | Correct | 9 ms | 16984 KB | Output is correct |
51 | Correct | 9 ms | 16984 KB | Output is correct |
52 | Correct | 8 ms | 17140 KB | Output is correct |
53 | Correct | 9 ms | 17116 KB | Output is correct |
54 | Correct | 9 ms | 17244 KB | Output is correct |
55 | Correct | 12 ms | 17752 KB | Output is correct |
56 | Correct | 27 ms | 20316 KB | Output is correct |
57 | Correct | 43 ms | 22864 KB | Output is correct |
58 | Correct | 65 ms | 24524 KB | Output is correct |
59 | Correct | 72 ms | 27084 KB | Output is correct |
60 | Correct | 91 ms | 29644 KB | Output is correct |
61 | Correct | 113 ms | 31692 KB | Output is correct |
62 | Correct | 122 ms | 33228 KB | Output is correct |
63 | Correct | 159 ms | 36228 KB | Output is correct |
64 | Correct | 151 ms | 37060 KB | Output is correct |
65 | Correct | 87 ms | 70992 KB | Output is correct |
66 | Correct | 88 ms | 71052 KB | Output is correct |
67 | Correct | 79 ms | 33388 KB | Output is correct |
68 | Correct | 124 ms | 53444 KB | Output is correct |
69 | Correct | 150 ms | 50624 KB | Output is correct |
70 | Correct | 146 ms | 50632 KB | Output is correct |
71 | Correct | 165 ms | 47804 KB | Output is correct |
72 | Correct | 166 ms | 48060 KB | Output is correct |
73 | Correct | 150 ms | 44004 KB | Output is correct |
74 | Correct | 153 ms | 44148 KB | Output is correct |
75 | Correct | 152 ms | 42652 KB | Output is correct |
76 | Correct | 151 ms | 42560 KB | Output is correct |
77 | Correct | 147 ms | 42432 KB | Output is correct |
78 | Correct | 160 ms | 40260 KB | Output is correct |
79 | Correct | 133 ms | 41408 KB | Output is correct |