답안 #684434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684434 2023-01-21T07:50:05 Z PoonYaPat Fireworks (APIO16_fireworks) C++14
100 / 100
218 ms 75636 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,m;
ll w[300001],ans;
vector<int> adj[300001];
priority_queue<ll> q[300001];

void dfs(int x) {

    if (adj[x].size()==0) {
        q[x].push(w[x]);
        q[x].push(w[x]);
        return;
    }

    for (auto s : adj[x]) {
        dfs(s);
        if (q[s].size()>q[x].size()) swap(q[s],q[x]);
        while (!q[s].empty()) q[x].push(q[s].top()), q[s].pop();
    }

    for (int i=1; i<adj[x].size(); ++i) q[x].pop();
    ll a=q[x].top()+w[x]; q[x].pop();
    ll b=q[x].top()+w[x]; q[x].pop();
    q[x].push(a); q[x].push(b);
}

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);
    }
    for (int i=1; i<=n+m; ++i) ans+=w[i];
    dfs(1);

    q[1].pop();
    while (!q[1].empty()) ans-=q[1].top(), q[1].pop();
    cout<<ans;
}

Compilation message

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i=1; i<adj[x].size(); ++i) q[x].pop();
      |                   ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16724 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 8 ms 16656 KB Output is correct
6 Correct 8 ms 16724 KB Output is correct
7 Correct 9 ms 16776 KB Output is correct
8 Correct 8 ms 16724 KB Output is correct
9 Correct 9 ms 16664 KB Output is correct
10 Correct 8 ms 16724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16760 KB Output is correct
2 Correct 8 ms 16764 KB Output is correct
3 Correct 10 ms 16772 KB Output is correct
4 Correct 8 ms 16724 KB Output is correct
5 Correct 8 ms 16724 KB Output is correct
6 Correct 8 ms 16712 KB Output is correct
7 Correct 8 ms 16680 KB Output is correct
8 Correct 8 ms 16724 KB Output is correct
9 Correct 10 ms 16724 KB Output is correct
10 Correct 8 ms 16724 KB Output is correct
11 Correct 8 ms 16700 KB Output is correct
12 Correct 9 ms 16760 KB Output is correct
13 Correct 9 ms 16764 KB Output is correct
14 Correct 9 ms 16724 KB Output is correct
15 Correct 8 ms 16768 KB Output is correct
16 Correct 9 ms 16724 KB Output is correct
17 Correct 8 ms 16704 KB Output is correct
18 Correct 8 ms 16680 KB Output is correct
19 Correct 9 ms 16724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16724 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 8 ms 16656 KB Output is correct
6 Correct 8 ms 16724 KB Output is correct
7 Correct 9 ms 16776 KB Output is correct
8 Correct 8 ms 16724 KB Output is correct
9 Correct 9 ms 16664 KB Output is correct
10 Correct 8 ms 16724 KB Output is correct
11 Correct 8 ms 16760 KB Output is correct
12 Correct 8 ms 16764 KB Output is correct
13 Correct 10 ms 16772 KB Output is correct
14 Correct 8 ms 16724 KB Output is correct
15 Correct 8 ms 16724 KB Output is correct
16 Correct 8 ms 16712 KB Output is correct
17 Correct 8 ms 16680 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 10 ms 16724 KB Output is correct
20 Correct 8 ms 16724 KB Output is correct
21 Correct 8 ms 16700 KB Output is correct
22 Correct 9 ms 16760 KB Output is correct
23 Correct 9 ms 16764 KB Output is correct
24 Correct 9 ms 16724 KB Output is correct
25 Correct 8 ms 16768 KB Output is correct
26 Correct 9 ms 16724 KB Output is correct
27 Correct 8 ms 16704 KB Output is correct
28 Correct 8 ms 16680 KB Output is correct
29 Correct 9 ms 16724 KB Output is correct
30 Correct 8 ms 16724 KB Output is correct
31 Correct 9 ms 16732 KB Output is correct
32 Correct 9 ms 16776 KB Output is correct
33 Correct 9 ms 16812 KB Output is correct
34 Correct 10 ms 16852 KB Output is correct
35 Correct 12 ms 16952 KB Output is correct
36 Correct 11 ms 16980 KB Output is correct
37 Correct 11 ms 16980 KB Output is correct
38 Correct 11 ms 17044 KB Output is correct
39 Correct 12 ms 17108 KB Output is correct
40 Correct 10 ms 17764 KB Output is correct
41 Correct 10 ms 17620 KB Output is correct
42 Correct 10 ms 17032 KB Output is correct
43 Correct 10 ms 17364 KB Output is correct
44 Correct 11 ms 17252 KB Output is correct
45 Correct 10 ms 17236 KB Output is correct
46 Correct 11 ms 17096 KB Output is correct
47 Correct 10 ms 17108 KB Output is correct
48 Correct 12 ms 17136 KB Output is correct
49 Correct 12 ms 17108 KB Output is correct
50 Correct 10 ms 16952 KB Output is correct
51 Correct 10 ms 17068 KB Output is correct
52 Correct 10 ms 17036 KB Output is correct
53 Correct 11 ms 17104 KB Output is correct
54 Correct 11 ms 17108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16724 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 8 ms 16656 KB Output is correct
6 Correct 8 ms 16724 KB Output is correct
7 Correct 9 ms 16776 KB Output is correct
8 Correct 8 ms 16724 KB Output is correct
9 Correct 9 ms 16664 KB Output is correct
10 Correct 8 ms 16724 KB Output is correct
11 Correct 8 ms 16760 KB Output is correct
12 Correct 8 ms 16764 KB Output is correct
13 Correct 10 ms 16772 KB Output is correct
14 Correct 8 ms 16724 KB Output is correct
15 Correct 8 ms 16724 KB Output is correct
16 Correct 8 ms 16712 KB Output is correct
17 Correct 8 ms 16680 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 10 ms 16724 KB Output is correct
20 Correct 8 ms 16724 KB Output is correct
21 Correct 8 ms 16700 KB Output is correct
22 Correct 9 ms 16760 KB Output is correct
23 Correct 9 ms 16764 KB Output is correct
24 Correct 9 ms 16724 KB Output is correct
25 Correct 8 ms 16768 KB Output is correct
26 Correct 9 ms 16724 KB Output is correct
27 Correct 8 ms 16704 KB Output is correct
28 Correct 8 ms 16680 KB Output is correct
29 Correct 9 ms 16724 KB Output is correct
30 Correct 8 ms 16724 KB Output is correct
31 Correct 9 ms 16732 KB Output is correct
32 Correct 9 ms 16776 KB Output is correct
33 Correct 9 ms 16812 KB Output is correct
34 Correct 10 ms 16852 KB Output is correct
35 Correct 12 ms 16952 KB Output is correct
36 Correct 11 ms 16980 KB Output is correct
37 Correct 11 ms 16980 KB Output is correct
38 Correct 11 ms 17044 KB Output is correct
39 Correct 12 ms 17108 KB Output is correct
40 Correct 10 ms 17764 KB Output is correct
41 Correct 10 ms 17620 KB Output is correct
42 Correct 10 ms 17032 KB Output is correct
43 Correct 10 ms 17364 KB Output is correct
44 Correct 11 ms 17252 KB Output is correct
45 Correct 10 ms 17236 KB Output is correct
46 Correct 11 ms 17096 KB Output is correct
47 Correct 10 ms 17108 KB Output is correct
48 Correct 12 ms 17136 KB Output is correct
49 Correct 12 ms 17108 KB Output is correct
50 Correct 10 ms 16952 KB Output is correct
51 Correct 10 ms 17068 KB Output is correct
52 Correct 10 ms 17036 KB Output is correct
53 Correct 11 ms 17104 KB Output is correct
54 Correct 11 ms 17108 KB Output is correct
55 Correct 15 ms 17676 KB Output is correct
56 Correct 34 ms 20236 KB Output is correct
57 Correct 61 ms 22656 KB Output is correct
58 Correct 79 ms 24220 KB Output is correct
59 Correct 102 ms 26816 KB Output is correct
60 Correct 127 ms 29204 KB Output is correct
61 Correct 146 ms 31348 KB Output is correct
62 Correct 169 ms 32744 KB Output is correct
63 Correct 210 ms 35756 KB Output is correct
64 Correct 218 ms 36544 KB Output is correct
65 Correct 111 ms 75544 KB Output is correct
66 Correct 113 ms 75636 KB Output is correct
67 Correct 108 ms 33412 KB Output is correct
68 Correct 166 ms 55840 KB Output is correct
69 Correct 184 ms 52392 KB Output is correct
70 Correct 187 ms 52236 KB Output is correct
71 Correct 203 ms 45768 KB Output is correct
72 Correct 207 ms 46132 KB Output is correct
73 Correct 180 ms 42344 KB Output is correct
74 Correct 187 ms 42396 KB Output is correct
75 Correct 183 ms 41404 KB Output is correct
76 Correct 182 ms 41440 KB Output is correct
77 Correct 188 ms 41020 KB Output is correct
78 Correct 198 ms 39148 KB Output is correct
79 Correct 177 ms 40148 KB Output is correct