# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
671074 | 2022-12-11T22:18:00 Z | AdamGS | Fireworks (APIO16_fireworks) | C++17 | 216 ms | 70920 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=3e5+7; vector<pair<int,ll>>V[LIM]; ll cnt[LIM], n, m, ans; void DFS1(int x) { cnt[x]=1; for(auto i : V[x]) { DFS1(i.st); cnt[x]+=cnt[i.st]; } rep(i, V[x].size()) if(cnt[V[x][i].st]>cnt[V[x][0].st]) swap(V[x][0], V[x][i]); } void DFS2(int x, ll k, priority_queue<ll>&q) { ans+=k; if(x>=n) { q.push(0); q.push(k); q.push(k); return; } DFS2(V[x][0].st, V[x][0].nd, q); for(int i=1; i<V[x].size(); ++i) { priority_queue<ll>p; DFS2(V[x][i].st, V[x][i].nd, p); while(!p.empty()) { q.push(p.top()); p.pop(); } } rep(i, V[x].size()-1) q.pop(); ll a=q.top(); q.pop(); ll b=q.top(); q.pop(); q.push(a+k); q.push(b+k); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rep(i, n+m-1) { ll a, b; cin >> a >> b; --a; V[a].pb({i+1, b}); } DFS1(0); priority_queue<ll>Q; DFS2(0, 0, Q); Q.pop(); vector<ll>P; while(!Q.empty()) { P.pb(Q.top()); Q.pop(); } for(ll i=P.size()-1; i; --i) ans-=i*(P[i-1]-P[i]); cout << ans << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7380 KB | Output is correct |
2 | Correct | 4 ms | 7252 KB | Output is correct |
3 | Correct | 4 ms | 7380 KB | Output is correct |
4 | Correct | 4 ms | 7376 KB | Output is correct |
5 | Correct | 4 ms | 7252 KB | Output is correct |
6 | Correct | 4 ms | 7368 KB | Output is correct |
7 | Correct | 4 ms | 7380 KB | Output is correct |
8 | Correct | 4 ms | 7380 KB | Output is correct |
9 | Correct | 4 ms | 7380 KB | Output is correct |
10 | Correct | 4 ms | 7380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7480 KB | Output is correct |
2 | Correct | 4 ms | 7372 KB | Output is correct |
3 | Correct | 4 ms | 7252 KB | Output is correct |
4 | Correct | 4 ms | 7380 KB | Output is correct |
5 | Correct | 4 ms | 7368 KB | Output is correct |
6 | Correct | 4 ms | 7380 KB | Output is correct |
7 | Correct | 4 ms | 7380 KB | Output is correct |
8 | Correct | 4 ms | 7380 KB | Output is correct |
9 | Correct | 4 ms | 7380 KB | Output is correct |
10 | Correct | 4 ms | 7372 KB | Output is correct |
11 | Correct | 4 ms | 7380 KB | Output is correct |
12 | Correct | 4 ms | 7380 KB | Output is correct |
13 | Correct | 4 ms | 7368 KB | Output is correct |
14 | Correct | 4 ms | 7316 KB | Output is correct |
15 | Correct | 4 ms | 7368 KB | Output is correct |
16 | Correct | 4 ms | 7308 KB | Output is correct |
17 | Correct | 4 ms | 7380 KB | Output is correct |
18 | Correct | 5 ms | 7368 KB | Output is correct |
19 | Correct | 5 ms | 7380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7380 KB | Output is correct |
2 | Correct | 4 ms | 7252 KB | Output is correct |
3 | Correct | 4 ms | 7380 KB | Output is correct |
4 | Correct | 4 ms | 7376 KB | Output is correct |
5 | Correct | 4 ms | 7252 KB | Output is correct |
6 | Correct | 4 ms | 7368 KB | Output is correct |
7 | Correct | 4 ms | 7380 KB | Output is correct |
8 | Correct | 4 ms | 7380 KB | Output is correct |
9 | Correct | 4 ms | 7380 KB | Output is correct |
10 | Correct | 4 ms | 7380 KB | Output is correct |
11 | Correct | 4 ms | 7480 KB | Output is correct |
12 | Correct | 4 ms | 7372 KB | Output is correct |
13 | Correct | 4 ms | 7252 KB | Output is correct |
14 | Correct | 4 ms | 7380 KB | Output is correct |
15 | Correct | 4 ms | 7368 KB | Output is correct |
16 | Correct | 4 ms | 7380 KB | Output is correct |
17 | Correct | 4 ms | 7380 KB | Output is correct |
18 | Correct | 4 ms | 7380 KB | Output is correct |
19 | Correct | 4 ms | 7380 KB | Output is correct |
20 | Correct | 4 ms | 7372 KB | Output is correct |
21 | Correct | 4 ms | 7380 KB | Output is correct |
22 | Correct | 4 ms | 7380 KB | Output is correct |
23 | Correct | 4 ms | 7368 KB | Output is correct |
24 | Correct | 4 ms | 7316 KB | Output is correct |
25 | Correct | 4 ms | 7368 KB | Output is correct |
26 | Correct | 4 ms | 7308 KB | Output is correct |
27 | Correct | 4 ms | 7380 KB | Output is correct |
28 | Correct | 5 ms | 7368 KB | Output is correct |
29 | Correct | 5 ms | 7380 KB | Output is correct |
30 | Correct | 4 ms | 7380 KB | Output is correct |
31 | Correct | 4 ms | 7380 KB | Output is correct |
32 | Correct | 5 ms | 7384 KB | Output is correct |
33 | Correct | 4 ms | 7508 KB | Output is correct |
34 | Correct | 5 ms | 7508 KB | Output is correct |
35 | Correct | 5 ms | 7636 KB | Output is correct |
36 | Correct | 6 ms | 7636 KB | Output is correct |
37 | Correct | 6 ms | 7716 KB | Output is correct |
38 | Correct | 6 ms | 7636 KB | Output is correct |
39 | Correct | 6 ms | 7640 KB | Output is correct |
40 | Correct | 6 ms | 8408 KB | Output is correct |
41 | Correct | 5 ms | 8404 KB | Output is correct |
42 | Correct | 5 ms | 7636 KB | Output is correct |
43 | Correct | 6 ms | 8024 KB | Output is correct |
44 | Correct | 7 ms | 8020 KB | Output is correct |
45 | Correct | 7 ms | 7980 KB | Output is correct |
46 | Correct | 7 ms | 7892 KB | Output is correct |
47 | Correct | 7 ms | 7892 KB | Output is correct |
48 | Correct | 6 ms | 7772 KB | Output is correct |
49 | Correct | 7 ms | 7800 KB | Output is correct |
50 | Correct | 6 ms | 7764 KB | Output is correct |
51 | Correct | 6 ms | 7780 KB | Output is correct |
52 | Correct | 6 ms | 7776 KB | Output is correct |
53 | Correct | 6 ms | 7764 KB | Output is correct |
54 | Correct | 7 ms | 7892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7380 KB | Output is correct |
2 | Correct | 4 ms | 7252 KB | Output is correct |
3 | Correct | 4 ms | 7380 KB | Output is correct |
4 | Correct | 4 ms | 7376 KB | Output is correct |
5 | Correct | 4 ms | 7252 KB | Output is correct |
6 | Correct | 4 ms | 7368 KB | Output is correct |
7 | Correct | 4 ms | 7380 KB | Output is correct |
8 | Correct | 4 ms | 7380 KB | Output is correct |
9 | Correct | 4 ms | 7380 KB | Output is correct |
10 | Correct | 4 ms | 7380 KB | Output is correct |
11 | Correct | 4 ms | 7480 KB | Output is correct |
12 | Correct | 4 ms | 7372 KB | Output is correct |
13 | Correct | 4 ms | 7252 KB | Output is correct |
14 | Correct | 4 ms | 7380 KB | Output is correct |
15 | Correct | 4 ms | 7368 KB | Output is correct |
16 | Correct | 4 ms | 7380 KB | Output is correct |
17 | Correct | 4 ms | 7380 KB | Output is correct |
18 | Correct | 4 ms | 7380 KB | Output is correct |
19 | Correct | 4 ms | 7380 KB | Output is correct |
20 | Correct | 4 ms | 7372 KB | Output is correct |
21 | Correct | 4 ms | 7380 KB | Output is correct |
22 | Correct | 4 ms | 7380 KB | Output is correct |
23 | Correct | 4 ms | 7368 KB | Output is correct |
24 | Correct | 4 ms | 7316 KB | Output is correct |
25 | Correct | 4 ms | 7368 KB | Output is correct |
26 | Correct | 4 ms | 7308 KB | Output is correct |
27 | Correct | 4 ms | 7380 KB | Output is correct |
28 | Correct | 5 ms | 7368 KB | Output is correct |
29 | Correct | 5 ms | 7380 KB | Output is correct |
30 | Correct | 4 ms | 7380 KB | Output is correct |
31 | Correct | 4 ms | 7380 KB | Output is correct |
32 | Correct | 5 ms | 7384 KB | Output is correct |
33 | Correct | 4 ms | 7508 KB | Output is correct |
34 | Correct | 5 ms | 7508 KB | Output is correct |
35 | Correct | 5 ms | 7636 KB | Output is correct |
36 | Correct | 6 ms | 7636 KB | Output is correct |
37 | Correct | 6 ms | 7716 KB | Output is correct |
38 | Correct | 6 ms | 7636 KB | Output is correct |
39 | Correct | 6 ms | 7640 KB | Output is correct |
40 | Correct | 6 ms | 8408 KB | Output is correct |
41 | Correct | 5 ms | 8404 KB | Output is correct |
42 | Correct | 5 ms | 7636 KB | Output is correct |
43 | Correct | 6 ms | 8024 KB | Output is correct |
44 | Correct | 7 ms | 8020 KB | Output is correct |
45 | Correct | 7 ms | 7980 KB | Output is correct |
46 | Correct | 7 ms | 7892 KB | Output is correct |
47 | Correct | 7 ms | 7892 KB | Output is correct |
48 | Correct | 6 ms | 7772 KB | Output is correct |
49 | Correct | 7 ms | 7800 KB | Output is correct |
50 | Correct | 6 ms | 7764 KB | Output is correct |
51 | Correct | 6 ms | 7780 KB | Output is correct |
52 | Correct | 6 ms | 7776 KB | Output is correct |
53 | Correct | 6 ms | 7764 KB | Output is correct |
54 | Correct | 7 ms | 7892 KB | Output is correct |
55 | Correct | 11 ms | 8284 KB | Output is correct |
56 | Correct | 29 ms | 11068 KB | Output is correct |
57 | Correct | 50 ms | 12872 KB | Output is correct |
58 | Correct | 73 ms | 15036 KB | Output is correct |
59 | Correct | 99 ms | 16936 KB | Output is correct |
60 | Correct | 123 ms | 18920 KB | Output is correct |
61 | Correct | 147 ms | 21872 KB | Output is correct |
62 | Correct | 166 ms | 23072 KB | Output is correct |
63 | Correct | 201 ms | 25512 KB | Output is correct |
64 | Correct | 206 ms | 26316 KB | Output is correct |
65 | Correct | 106 ms | 70920 KB | Output is correct |
66 | Correct | 109 ms | 70840 KB | Output is correct |
67 | Correct | 97 ms | 24088 KB | Output is correct |
68 | Correct | 170 ms | 53512 KB | Output is correct |
69 | Correct | 200 ms | 50236 KB | Output is correct |
70 | Correct | 197 ms | 50224 KB | Output is correct |
71 | Correct | 213 ms | 37848 KB | Output is correct |
72 | Correct | 213 ms | 37808 KB | Output is correct |
73 | Correct | 204 ms | 36708 KB | Output is correct |
74 | Correct | 196 ms | 36900 KB | Output is correct |
75 | Correct | 196 ms | 35976 KB | Output is correct |
76 | Correct | 197 ms | 36056 KB | Output is correct |
77 | Correct | 200 ms | 36244 KB | Output is correct |
78 | Correct | 216 ms | 35912 KB | Output is correct |
79 | Correct | 201 ms | 37300 KB | Output is correct |