# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
950185 | 2024-03-20T06:35:08 Z | abczz | Fireworks (APIO16_fireworks) | C++14 | 336 ms | 89944 KB |
#include <iostream> #include <vector> #include <array> #include <map> #include <queue> #include <algorithm> #define ll long long using namespace std; priority_queue<ll> pq[300000]; vector <ll> V; vector <array<ll, 2> > adj[300000]; ll n, m, f, k, s, p, P[300000]; void dfs(ll u) { ll mx = 0, id = -1, z; for (auto [v, x] : adj[u]) { dfs(v); if (pq[v].size() > mx) { mx = pq[v].size(); id = v, z = x; } } if (id != -1) { swap(pq[u], pq[id]); auto a = pq[u].top(); pq[u].pop(); auto b = pq[u].top(); pq[u].pop(); pq[u].push(a+z); pq[u].push(b+z); } for (auto [v, x] : adj[u]) { if (v != id) { auto a = pq[v].top(); pq[v].pop(); auto b = pq[v].top(); pq[v].pop(); pq[v].push(a+x); pq[v].push(b+x); while (!pq[v].empty()) { auto y = pq[v].top(); pq[v].pop(); pq[u].push(y); } } } for (int i=1; i<adj[u].size(); ++i) { pq[u].pop(); } if (adj[u].empty()) { for (int i=0; i<2; ++i) { pq[u].push(0); } } } int main() { cin >> n >> m; for (int i=1; i<n+m; ++i) { cin >> P[i] >> k; s += k; --P[i]; adj[P[i]].push_back({i, k}); } dfs(0); while (!pq[0].empty()) { auto u = pq[0].top(); V.push_back(u); pq[0].pop(); } V.push_back(0); for (ll i=0; i+1<V.size(); ++i) { s -= (V[i]-V[i+1]) * i; } cout << s << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 16984 KB | Output is correct |
2 | Correct | 4 ms | 16984 KB | Output is correct |
3 | Correct | 4 ms | 17008 KB | Output is correct |
4 | Correct | 5 ms | 16988 KB | Output is correct |
5 | Correct | 4 ms | 16988 KB | Output is correct |
6 | Correct | 4 ms | 16984 KB | Output is correct |
7 | Correct | 4 ms | 16988 KB | Output is correct |
8 | Correct | 3 ms | 16988 KB | Output is correct |
9 | Correct | 4 ms | 16988 KB | Output is correct |
10 | Correct | 5 ms | 16988 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 16984 KB | Output is correct |
2 | Correct | 5 ms | 17240 KB | Output is correct |
3 | Correct | 4 ms | 16988 KB | Output is correct |
4 | Correct | 5 ms | 16988 KB | Output is correct |
5 | Correct | 4 ms | 16988 KB | Output is correct |
6 | Correct | 4 ms | 16996 KB | Output is correct |
7 | Correct | 4 ms | 16984 KB | Output is correct |
8 | Correct | 4 ms | 16988 KB | Output is correct |
9 | Correct | 4 ms | 16988 KB | Output is correct |
10 | Correct | 4 ms | 16984 KB | Output is correct |
11 | Correct | 5 ms | 17000 KB | Output is correct |
12 | Correct | 4 ms | 16988 KB | Output is correct |
13 | Correct | 5 ms | 17012 KB | Output is correct |
14 | Correct | 4 ms | 16988 KB | Output is correct |
15 | Correct | 4 ms | 16992 KB | Output is correct |
16 | Correct | 4 ms | 17008 KB | Output is correct |
17 | Correct | 4 ms | 16988 KB | Output is correct |
18 | Correct | 4 ms | 16988 KB | Output is correct |
19 | Correct | 4 ms | 16984 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 16984 KB | Output is correct |
2 | Correct | 4 ms | 16984 KB | Output is correct |
3 | Correct | 4 ms | 17008 KB | Output is correct |
4 | Correct | 5 ms | 16988 KB | Output is correct |
5 | Correct | 4 ms | 16988 KB | Output is correct |
6 | Correct | 4 ms | 16984 KB | Output is correct |
7 | Correct | 4 ms | 16988 KB | Output is correct |
8 | Correct | 3 ms | 16988 KB | Output is correct |
9 | Correct | 4 ms | 16988 KB | Output is correct |
10 | Correct | 5 ms | 16988 KB | Output is correct |
11 | Correct | 4 ms | 16984 KB | Output is correct |
12 | Correct | 5 ms | 17240 KB | Output is correct |
13 | Correct | 4 ms | 16988 KB | Output is correct |
14 | Correct | 5 ms | 16988 KB | Output is correct |
15 | Correct | 4 ms | 16988 KB | Output is correct |
16 | Correct | 4 ms | 16996 KB | Output is correct |
17 | Correct | 4 ms | 16984 KB | Output is correct |
18 | Correct | 4 ms | 16988 KB | Output is correct |
19 | Correct | 4 ms | 16988 KB | Output is correct |
20 | Correct | 4 ms | 16984 KB | Output is correct |
21 | Correct | 5 ms | 17000 KB | Output is correct |
22 | Correct | 4 ms | 16988 KB | Output is correct |
23 | Correct | 5 ms | 17012 KB | Output is correct |
24 | Correct | 4 ms | 16988 KB | Output is correct |
25 | Correct | 4 ms | 16992 KB | Output is correct |
26 | Correct | 4 ms | 17008 KB | Output is correct |
27 | Correct | 4 ms | 16988 KB | Output is correct |
28 | Correct | 4 ms | 16988 KB | Output is correct |
29 | Correct | 4 ms | 16984 KB | Output is correct |
30 | Correct | 4 ms | 16984 KB | Output is correct |
31 | Correct | 5 ms | 16988 KB | Output is correct |
32 | Correct | 6 ms | 17240 KB | Output is correct |
33 | Correct | 5 ms | 16988 KB | Output is correct |
34 | Correct | 6 ms | 17244 KB | Output is correct |
35 | Correct | 6 ms | 17244 KB | Output is correct |
36 | Correct | 7 ms | 17272 KB | Output is correct |
37 | Correct | 7 ms | 17244 KB | Output is correct |
38 | Correct | 8 ms | 17244 KB | Output is correct |
39 | Correct | 7 ms | 17268 KB | Output is correct |
40 | Correct | 7 ms | 18012 KB | Output is correct |
41 | Correct | 10 ms | 18208 KB | Output is correct |
42 | Correct | 8 ms | 17244 KB | Output is correct |
43 | Correct | 9 ms | 17952 KB | Output is correct |
44 | Correct | 7 ms | 17500 KB | Output is correct |
45 | Correct | 8 ms | 17496 KB | Output is correct |
46 | Correct | 7 ms | 17496 KB | Output is correct |
47 | Correct | 8 ms | 17500 KB | Output is correct |
48 | Correct | 7 ms | 17524 KB | Output is correct |
49 | Correct | 7 ms | 17496 KB | Output is correct |
50 | Correct | 7 ms | 17240 KB | Output is correct |
51 | Correct | 8 ms | 17244 KB | Output is correct |
52 | Correct | 7 ms | 17272 KB | Output is correct |
53 | Correct | 7 ms | 17500 KB | Output is correct |
54 | Correct | 8 ms | 17500 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 16984 KB | Output is correct |
2 | Correct | 4 ms | 16984 KB | Output is correct |
3 | Correct | 4 ms | 17008 KB | Output is correct |
4 | Correct | 5 ms | 16988 KB | Output is correct |
5 | Correct | 4 ms | 16988 KB | Output is correct |
6 | Correct | 4 ms | 16984 KB | Output is correct |
7 | Correct | 4 ms | 16988 KB | Output is correct |
8 | Correct | 3 ms | 16988 KB | Output is correct |
9 | Correct | 4 ms | 16988 KB | Output is correct |
10 | Correct | 5 ms | 16988 KB | Output is correct |
11 | Correct | 4 ms | 16984 KB | Output is correct |
12 | Correct | 5 ms | 17240 KB | Output is correct |
13 | Correct | 4 ms | 16988 KB | Output is correct |
14 | Correct | 5 ms | 16988 KB | Output is correct |
15 | Correct | 4 ms | 16988 KB | Output is correct |
16 | Correct | 4 ms | 16996 KB | Output is correct |
17 | Correct | 4 ms | 16984 KB | Output is correct |
18 | Correct | 4 ms | 16988 KB | Output is correct |
19 | Correct | 4 ms | 16988 KB | Output is correct |
20 | Correct | 4 ms | 16984 KB | Output is correct |
21 | Correct | 5 ms | 17000 KB | Output is correct |
22 | Correct | 4 ms | 16988 KB | Output is correct |
23 | Correct | 5 ms | 17012 KB | Output is correct |
24 | Correct | 4 ms | 16988 KB | Output is correct |
25 | Correct | 4 ms | 16992 KB | Output is correct |
26 | Correct | 4 ms | 17008 KB | Output is correct |
27 | Correct | 4 ms | 16988 KB | Output is correct |
28 | Correct | 4 ms | 16988 KB | Output is correct |
29 | Correct | 4 ms | 16984 KB | Output is correct |
30 | Correct | 4 ms | 16984 KB | Output is correct |
31 | Correct | 5 ms | 16988 KB | Output is correct |
32 | Correct | 6 ms | 17240 KB | Output is correct |
33 | Correct | 5 ms | 16988 KB | Output is correct |
34 | Correct | 6 ms | 17244 KB | Output is correct |
35 | Correct | 6 ms | 17244 KB | Output is correct |
36 | Correct | 7 ms | 17272 KB | Output is correct |
37 | Correct | 7 ms | 17244 KB | Output is correct |
38 | Correct | 8 ms | 17244 KB | Output is correct |
39 | Correct | 7 ms | 17268 KB | Output is correct |
40 | Correct | 7 ms | 18012 KB | Output is correct |
41 | Correct | 10 ms | 18208 KB | Output is correct |
42 | Correct | 8 ms | 17244 KB | Output is correct |
43 | Correct | 9 ms | 17952 KB | Output is correct |
44 | Correct | 7 ms | 17500 KB | Output is correct |
45 | Correct | 8 ms | 17496 KB | Output is correct |
46 | Correct | 7 ms | 17496 KB | Output is correct |
47 | Correct | 8 ms | 17500 KB | Output is correct |
48 | Correct | 7 ms | 17524 KB | Output is correct |
49 | Correct | 7 ms | 17496 KB | Output is correct |
50 | Correct | 7 ms | 17240 KB | Output is correct |
51 | Correct | 8 ms | 17244 KB | Output is correct |
52 | Correct | 7 ms | 17272 KB | Output is correct |
53 | Correct | 7 ms | 17500 KB | Output is correct |
54 | Correct | 8 ms | 17500 KB | Output is correct |
55 | Correct | 14 ms | 18004 KB | Output is correct |
56 | Correct | 45 ms | 22928 KB | Output is correct |
57 | Correct | 72 ms | 25364 KB | Output is correct |
58 | Correct | 94 ms | 27340 KB | Output is correct |
59 | Correct | 126 ms | 29896 KB | Output is correct |
60 | Correct | 162 ms | 32372 KB | Output is correct |
61 | Correct | 192 ms | 34756 KB | Output is correct |
62 | Correct | 213 ms | 36408 KB | Output is correct |
63 | Correct | 336 ms | 39384 KB | Output is correct |
64 | Correct | 285 ms | 40388 KB | Output is correct |
65 | Correct | 212 ms | 89944 KB | Output is correct |
66 | Correct | 207 ms | 89804 KB | Output is correct |
67 | Correct | 217 ms | 33412 KB | Output is correct |
68 | Correct | 261 ms | 68028 KB | Output is correct |
69 | Correct | 293 ms | 63856 KB | Output is correct |
70 | Correct | 284 ms | 63836 KB | Output is correct |
71 | Correct | 269 ms | 59424 KB | Output is correct |
72 | Correct | 267 ms | 56980 KB | Output is correct |
73 | Correct | 293 ms | 57172 KB | Output is correct |
74 | Correct | 243 ms | 53432 KB | Output is correct |
75 | Correct | 250 ms | 51940 KB | Output is correct |
76 | Correct | 242 ms | 55192 KB | Output is correct |
77 | Correct | 253 ms | 50296 KB | Output is correct |
78 | Correct | 244 ms | 51900 KB | Output is correct |
79 | Correct | 236 ms | 51884 KB | Output is correct |