답안 #982169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982169 2024-05-14T01:54:15 Z 12345678 Fireworks (APIO16_fireworks) C++17
100 / 100
185 ms 94520 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=6e5+5;

#define ll long long

ll n, m, p, x, res;
vector<pair<ll, ll>> d[nx];
priority_queue<ll> pq[nx];

void dfs(int u)
{
    for (auto [v, w]:d[u])
    {
        dfs(v);
        res+=w;
        ll a=pq[v].top();
        pq[v].pop();
        ll b=pq[v].top();
        pq[v].pop();
        pq[v].push(a+w);
        pq[v].push(b+w);
        if (pq[v].size()>pq[u].size()) swap(pq[u], pq[v]);
        while (!pq[v].empty()) pq[u].push(pq[v].top()), pq[v].pop();
    }
    for (int i=1; i<d[u].size(); i++) pq[u].pop();
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=2; i<=n+m; i++) cin>>p>>x, d[p].push_back({i, x});
    for (int i=n+1; i<=n+m; i++) pq[i].push(0), pq[i].push(0);
    dfs(1);
    pq[1].pop();
    while (!pq[1].empty()) res-=pq[1].top(), pq[1].pop();
    cout<<res;
}

Compilation message

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i=1; i<d[u].size(); i++) pq[u].pop();
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 33116 KB Output is correct
2 Correct 7 ms 33116 KB Output is correct
3 Correct 8 ms 33116 KB Output is correct
4 Correct 8 ms 33116 KB Output is correct
5 Correct 8 ms 33116 KB Output is correct
6 Correct 8 ms 33212 KB Output is correct
7 Correct 7 ms 33112 KB Output is correct
8 Correct 7 ms 33116 KB Output is correct
9 Correct 8 ms 33116 KB Output is correct
10 Correct 8 ms 33116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 33116 KB Output is correct
2 Correct 8 ms 33268 KB Output is correct
3 Correct 10 ms 33372 KB Output is correct
4 Correct 8 ms 33116 KB Output is correct
5 Correct 8 ms 33112 KB Output is correct
6 Correct 8 ms 33372 KB Output is correct
7 Correct 8 ms 33116 KB Output is correct
8 Correct 8 ms 33116 KB Output is correct
9 Correct 8 ms 33344 KB Output is correct
10 Correct 8 ms 33112 KB Output is correct
11 Correct 8 ms 33112 KB Output is correct
12 Correct 7 ms 33332 KB Output is correct
13 Correct 8 ms 33116 KB Output is correct
14 Correct 8 ms 33372 KB Output is correct
15 Correct 8 ms 33116 KB Output is correct
16 Correct 8 ms 33116 KB Output is correct
17 Correct 8 ms 33300 KB Output is correct
18 Correct 8 ms 33116 KB Output is correct
19 Correct 8 ms 33276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 33116 KB Output is correct
2 Correct 7 ms 33116 KB Output is correct
3 Correct 8 ms 33116 KB Output is correct
4 Correct 8 ms 33116 KB Output is correct
5 Correct 8 ms 33116 KB Output is correct
6 Correct 8 ms 33212 KB Output is correct
7 Correct 7 ms 33112 KB Output is correct
8 Correct 7 ms 33116 KB Output is correct
9 Correct 8 ms 33116 KB Output is correct
10 Correct 8 ms 33116 KB Output is correct
11 Correct 8 ms 33116 KB Output is correct
12 Correct 8 ms 33268 KB Output is correct
13 Correct 10 ms 33372 KB Output is correct
14 Correct 8 ms 33116 KB Output is correct
15 Correct 8 ms 33112 KB Output is correct
16 Correct 8 ms 33372 KB Output is correct
17 Correct 8 ms 33116 KB Output is correct
18 Correct 8 ms 33116 KB Output is correct
19 Correct 8 ms 33344 KB Output is correct
20 Correct 8 ms 33112 KB Output is correct
21 Correct 8 ms 33112 KB Output is correct
22 Correct 7 ms 33332 KB Output is correct
23 Correct 8 ms 33116 KB Output is correct
24 Correct 8 ms 33372 KB Output is correct
25 Correct 8 ms 33116 KB Output is correct
26 Correct 8 ms 33116 KB Output is correct
27 Correct 8 ms 33300 KB Output is correct
28 Correct 8 ms 33116 KB Output is correct
29 Correct 8 ms 33276 KB Output is correct
30 Correct 8 ms 33116 KB Output is correct
31 Correct 8 ms 33372 KB Output is correct
32 Correct 9 ms 33372 KB Output is correct
33 Correct 9 ms 33568 KB Output is correct
34 Correct 9 ms 33372 KB Output is correct
35 Correct 9 ms 33372 KB Output is correct
36 Correct 11 ms 33720 KB Output is correct
37 Correct 9 ms 33628 KB Output is correct
38 Correct 9 ms 33628 KB Output is correct
39 Correct 10 ms 33628 KB Output is correct
40 Correct 9 ms 34140 KB Output is correct
41 Correct 9 ms 34140 KB Output is correct
42 Correct 9 ms 33556 KB Output is correct
43 Correct 10 ms 33884 KB Output is correct
44 Correct 10 ms 33800 KB Output is correct
45 Correct 10 ms 33880 KB Output is correct
46 Correct 10 ms 33628 KB Output is correct
47 Correct 10 ms 33780 KB Output is correct
48 Correct 10 ms 33700 KB Output is correct
49 Correct 11 ms 33624 KB Output is correct
50 Correct 9 ms 33628 KB Output is correct
51 Correct 10 ms 33624 KB Output is correct
52 Correct 10 ms 33624 KB Output is correct
53 Correct 10 ms 33628 KB Output is correct
54 Correct 11 ms 33628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 33116 KB Output is correct
2 Correct 7 ms 33116 KB Output is correct
3 Correct 8 ms 33116 KB Output is correct
4 Correct 8 ms 33116 KB Output is correct
5 Correct 8 ms 33116 KB Output is correct
6 Correct 8 ms 33212 KB Output is correct
7 Correct 7 ms 33112 KB Output is correct
8 Correct 7 ms 33116 KB Output is correct
9 Correct 8 ms 33116 KB Output is correct
10 Correct 8 ms 33116 KB Output is correct
11 Correct 8 ms 33116 KB Output is correct
12 Correct 8 ms 33268 KB Output is correct
13 Correct 10 ms 33372 KB Output is correct
14 Correct 8 ms 33116 KB Output is correct
15 Correct 8 ms 33112 KB Output is correct
16 Correct 8 ms 33372 KB Output is correct
17 Correct 8 ms 33116 KB Output is correct
18 Correct 8 ms 33116 KB Output is correct
19 Correct 8 ms 33344 KB Output is correct
20 Correct 8 ms 33112 KB Output is correct
21 Correct 8 ms 33112 KB Output is correct
22 Correct 7 ms 33332 KB Output is correct
23 Correct 8 ms 33116 KB Output is correct
24 Correct 8 ms 33372 KB Output is correct
25 Correct 8 ms 33116 KB Output is correct
26 Correct 8 ms 33116 KB Output is correct
27 Correct 8 ms 33300 KB Output is correct
28 Correct 8 ms 33116 KB Output is correct
29 Correct 8 ms 33276 KB Output is correct
30 Correct 8 ms 33116 KB Output is correct
31 Correct 8 ms 33372 KB Output is correct
32 Correct 9 ms 33372 KB Output is correct
33 Correct 9 ms 33568 KB Output is correct
34 Correct 9 ms 33372 KB Output is correct
35 Correct 9 ms 33372 KB Output is correct
36 Correct 11 ms 33720 KB Output is correct
37 Correct 9 ms 33628 KB Output is correct
38 Correct 9 ms 33628 KB Output is correct
39 Correct 10 ms 33628 KB Output is correct
40 Correct 9 ms 34140 KB Output is correct
41 Correct 9 ms 34140 KB Output is correct
42 Correct 9 ms 33556 KB Output is correct
43 Correct 10 ms 33884 KB Output is correct
44 Correct 10 ms 33800 KB Output is correct
45 Correct 10 ms 33880 KB Output is correct
46 Correct 10 ms 33628 KB Output is correct
47 Correct 10 ms 33780 KB Output is correct
48 Correct 10 ms 33700 KB Output is correct
49 Correct 11 ms 33624 KB Output is correct
50 Correct 9 ms 33628 KB Output is correct
51 Correct 10 ms 33624 KB Output is correct
52 Correct 10 ms 33624 KB Output is correct
53 Correct 10 ms 33628 KB Output is correct
54 Correct 11 ms 33628 KB Output is correct
55 Correct 13 ms 34140 KB Output is correct
56 Correct 29 ms 36692 KB Output is correct
57 Correct 45 ms 39252 KB Output is correct
58 Correct 56 ms 40968 KB Output is correct
59 Correct 79 ms 43308 KB Output is correct
60 Correct 100 ms 46020 KB Output is correct
61 Correct 118 ms 48132 KB Output is correct
62 Correct 149 ms 49628 KB Output is correct
63 Correct 167 ms 52424 KB Output is correct
64 Correct 185 ms 53472 KB Output is correct
65 Correct 94 ms 94520 KB Output is correct
66 Correct 98 ms 94372 KB Output is correct
67 Correct 76 ms 47700 KB Output is correct
68 Correct 142 ms 75432 KB Output is correct
69 Correct 163 ms 71916 KB Output is correct
70 Correct 169 ms 71872 KB Output is correct
71 Correct 168 ms 67188 KB Output is correct
72 Correct 173 ms 66420 KB Output is correct
73 Correct 150 ms 62404 KB Output is correct
74 Correct 151 ms 64208 KB Output is correct
75 Correct 152 ms 60980 KB Output is correct
76 Correct 152 ms 61920 KB Output is correct
77 Correct 156 ms 61256 KB Output is correct
78 Correct 153 ms 59288 KB Output is correct
79 Correct 145 ms 65352 KB Output is correct