Submission #714933

# Submission time Handle Problem Language Result Execution time Memory
714933 2023-03-25T14:17:12 Z Spade1 Fireworks (APIO16_fireworks) C++14
100 / 100
228 ms 75620 KB
#include<bits/stdc++.h>
//#include <grader.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

const int N = 3e5 + 10;

vector<int> adj[N];
priority_queue<ll> q[N];
ll c[N];

void dfs(int i) {
    if (adj[i].empty()) {
        q[i].push(c[i]);
        q[i].push(c[i]);
        return;
    }
    for (auto j : adj[i]) {
        dfs(j);
        if (q[i].size() < q[j].size()) swap(q[i], q[j]);
        while (!q[j].empty()) q[i].push(q[j].top()), q[j].pop();
    }
    for (int k = 1; k < adj[i].size(); ++k) q[i].pop();
    ll a = q[i].top()+c[i]; q[i].pop();
    ll b = q[i].top()+c[i]; q[i].pop();
    q[i].push(a); q[i].push(b);
}

void solve() {
    int n, m; cin >> n >> m;
    for (int i = 2; i <= n+m; ++i) {
        int p; cin >> p >> c[i];
        adj[p].pb(i);
    }
    ll ans = 0;
    for (int i = 2; i <= n+m; ++i) ans += c[i];
    dfs(1);
    q[1].pop();
    while (!q[1].empty()) ans -= q[1].top(), q[1].pop();
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Compilation message

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int k = 1; k < adj[i].size(); ++k) q[i].pop();
      |                     ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 9 ms 16764 KB Output is correct
3 Correct 8 ms 16772 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 9 ms 16784 KB Output is correct
6 Correct 8 ms 16724 KB Output is correct
7 Correct 9 ms 16764 KB Output is correct
8 Correct 9 ms 16720 KB Output is correct
9 Correct 9 ms 16724 KB Output is correct
10 Correct 9 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16716 KB Output is correct
2 Correct 9 ms 16684 KB Output is correct
3 Correct 10 ms 16724 KB Output is correct
4 Correct 8 ms 16724 KB Output is correct
5 Correct 9 ms 16724 KB Output is correct
6 Correct 9 ms 16724 KB Output is correct
7 Correct 8 ms 16724 KB Output is correct
8 Correct 8 ms 16724 KB Output is correct
9 Correct 10 ms 16724 KB Output is correct
10 Correct 10 ms 16724 KB Output is correct
11 Correct 9 ms 16712 KB Output is correct
12 Correct 9 ms 16724 KB Output is correct
13 Correct 8 ms 16768 KB Output is correct
14 Correct 9 ms 16720 KB Output is correct
15 Correct 9 ms 16796 KB Output is correct
16 Correct 9 ms 16724 KB Output is correct
17 Correct 9 ms 16724 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 10 ms 16700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 9 ms 16764 KB Output is correct
3 Correct 8 ms 16772 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 9 ms 16784 KB Output is correct
6 Correct 8 ms 16724 KB Output is correct
7 Correct 9 ms 16764 KB Output is correct
8 Correct 9 ms 16720 KB Output is correct
9 Correct 9 ms 16724 KB Output is correct
10 Correct 9 ms 16724 KB Output is correct
11 Correct 8 ms 16716 KB Output is correct
12 Correct 9 ms 16684 KB Output is correct
13 Correct 10 ms 16724 KB Output is correct
14 Correct 8 ms 16724 KB Output is correct
15 Correct 9 ms 16724 KB Output is correct
16 Correct 9 ms 16724 KB Output is correct
17 Correct 8 ms 16724 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 10 ms 16724 KB Output is correct
20 Correct 10 ms 16724 KB Output is correct
21 Correct 9 ms 16712 KB Output is correct
22 Correct 9 ms 16724 KB Output is correct
23 Correct 8 ms 16768 KB Output is correct
24 Correct 9 ms 16720 KB Output is correct
25 Correct 9 ms 16796 KB Output is correct
26 Correct 9 ms 16724 KB Output is correct
27 Correct 9 ms 16724 KB Output is correct
28 Correct 8 ms 16724 KB Output is correct
29 Correct 10 ms 16700 KB Output is correct
30 Correct 9 ms 16852 KB Output is correct
31 Correct 10 ms 16824 KB Output is correct
32 Correct 10 ms 16900 KB Output is correct
33 Correct 10 ms 16904 KB Output is correct
34 Correct 9 ms 16980 KB Output is correct
35 Correct 11 ms 17000 KB Output is correct
36 Correct 13 ms 16980 KB Output is correct
37 Correct 12 ms 17040 KB Output is correct
38 Correct 13 ms 17236 KB Output is correct
39 Correct 12 ms 17108 KB Output is correct
40 Correct 11 ms 17672 KB Output is correct
41 Correct 10 ms 17620 KB Output is correct
42 Correct 11 ms 17052 KB Output is correct
43 Correct 11 ms 17296 KB Output is correct
44 Correct 14 ms 17296 KB Output is correct
45 Correct 11 ms 17312 KB Output is correct
46 Correct 11 ms 17172 KB Output is correct
47 Correct 11 ms 17108 KB Output is correct
48 Correct 12 ms 17076 KB Output is correct
49 Correct 11 ms 17108 KB Output is correct
50 Correct 12 ms 17064 KB Output is correct
51 Correct 10 ms 16980 KB Output is correct
52 Correct 11 ms 17108 KB Output is correct
53 Correct 11 ms 17160 KB Output is correct
54 Correct 11 ms 17108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 9 ms 16764 KB Output is correct
3 Correct 8 ms 16772 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 9 ms 16784 KB Output is correct
6 Correct 8 ms 16724 KB Output is correct
7 Correct 9 ms 16764 KB Output is correct
8 Correct 9 ms 16720 KB Output is correct
9 Correct 9 ms 16724 KB Output is correct
10 Correct 9 ms 16724 KB Output is correct
11 Correct 8 ms 16716 KB Output is correct
12 Correct 9 ms 16684 KB Output is correct
13 Correct 10 ms 16724 KB Output is correct
14 Correct 8 ms 16724 KB Output is correct
15 Correct 9 ms 16724 KB Output is correct
16 Correct 9 ms 16724 KB Output is correct
17 Correct 8 ms 16724 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 10 ms 16724 KB Output is correct
20 Correct 10 ms 16724 KB Output is correct
21 Correct 9 ms 16712 KB Output is correct
22 Correct 9 ms 16724 KB Output is correct
23 Correct 8 ms 16768 KB Output is correct
24 Correct 9 ms 16720 KB Output is correct
25 Correct 9 ms 16796 KB Output is correct
26 Correct 9 ms 16724 KB Output is correct
27 Correct 9 ms 16724 KB Output is correct
28 Correct 8 ms 16724 KB Output is correct
29 Correct 10 ms 16700 KB Output is correct
30 Correct 9 ms 16852 KB Output is correct
31 Correct 10 ms 16824 KB Output is correct
32 Correct 10 ms 16900 KB Output is correct
33 Correct 10 ms 16904 KB Output is correct
34 Correct 9 ms 16980 KB Output is correct
35 Correct 11 ms 17000 KB Output is correct
36 Correct 13 ms 16980 KB Output is correct
37 Correct 12 ms 17040 KB Output is correct
38 Correct 13 ms 17236 KB Output is correct
39 Correct 12 ms 17108 KB Output is correct
40 Correct 11 ms 17672 KB Output is correct
41 Correct 10 ms 17620 KB Output is correct
42 Correct 11 ms 17052 KB Output is correct
43 Correct 11 ms 17296 KB Output is correct
44 Correct 14 ms 17296 KB Output is correct
45 Correct 11 ms 17312 KB Output is correct
46 Correct 11 ms 17172 KB Output is correct
47 Correct 11 ms 17108 KB Output is correct
48 Correct 12 ms 17076 KB Output is correct
49 Correct 11 ms 17108 KB Output is correct
50 Correct 12 ms 17064 KB Output is correct
51 Correct 10 ms 16980 KB Output is correct
52 Correct 11 ms 17108 KB Output is correct
53 Correct 11 ms 17160 KB Output is correct
54 Correct 11 ms 17108 KB Output is correct
55 Correct 15 ms 17620 KB Output is correct
56 Correct 36 ms 20172 KB Output is correct
57 Correct 63 ms 22568 KB Output is correct
58 Correct 83 ms 24220 KB Output is correct
59 Correct 117 ms 26932 KB Output is correct
60 Correct 139 ms 29200 KB Output is correct
61 Correct 158 ms 31404 KB Output is correct
62 Correct 179 ms 32808 KB Output is correct
63 Correct 217 ms 35760 KB Output is correct
64 Correct 228 ms 36688 KB Output is correct
65 Correct 113 ms 75516 KB Output is correct
66 Correct 116 ms 75620 KB Output is correct
67 Correct 111 ms 33420 KB Output is correct
68 Correct 169 ms 55820 KB Output is correct
69 Correct 198 ms 52168 KB Output is correct
70 Correct 193 ms 52292 KB Output is correct
71 Correct 195 ms 45768 KB Output is correct
72 Correct 199 ms 46256 KB Output is correct
73 Correct 179 ms 42272 KB Output is correct
74 Correct 181 ms 42416 KB Output is correct
75 Correct 181 ms 41400 KB Output is correct
76 Correct 188 ms 41580 KB Output is correct
77 Correct 192 ms 41056 KB Output is correct
78 Correct 193 ms 39064 KB Output is correct
79 Correct 181 ms 40172 KB Output is correct