답안 #952920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952920 2024-03-25T05:06:24 Z ttamx Fireworks (APIO16_fireworks) C++17
100 / 100
225 ms 99156 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

const int N=6e5+5;

int n,m;
vector<pair<int,int>> adj[N];
priority_queue<ll> dp[N];
ll ans;

void dfs(int u){
    for(auto [v,w]:adj[u]){
        dfs(v);
        ll x=dp[v].top();
        dp[v].pop();
        ll y=dp[v].top();
        dp[v].pop();
        dp[v].emplace(x+w),dp[v].emplace(y+w);
        if(dp[v].size()>dp[u].size())swap(dp[u],dp[v]);
        while(!dp[v].empty()){
            dp[u].emplace(dp[v].top());
            dp[v].pop();
        }
    }
    for(int i=1;i<adj[u].size();i++)dp[u].pop();
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> m;
    for(int i=2;i<=n+m;i++){
        int p,c;
        cin >> p >> c;
        adj[p].emplace_back(i,c);
        ans+=c;
    }
    for(int i=1;i<=m;i++){
        dp[n+i].emplace(0);
        dp[n+i].emplace(0);
    }
    dfs(1);
    dp[1].pop();
    while(!dp[1].empty()){
        ans-=dp[1].top();
        dp[1].pop();
    }
    cout << ans;
}

Compilation message

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=1;i<adj[u].size();i++)dp[u].pop();
      |                 ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 33308 KB Output is correct
2 Correct 8 ms 33328 KB Output is correct
3 Correct 10 ms 33116 KB Output is correct
4 Correct 8 ms 33116 KB Output is correct
5 Correct 9 ms 33112 KB Output is correct
6 Correct 9 ms 33112 KB Output is correct
7 Correct 8 ms 33116 KB Output is correct
8 Correct 14 ms 33136 KB Output is correct
9 Correct 12 ms 33116 KB Output is correct
10 Correct 16 ms 33208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 33360 KB Output is correct
2 Correct 15 ms 33156 KB Output is correct
3 Correct 15 ms 33112 KB Output is correct
4 Correct 21 ms 33112 KB Output is correct
5 Correct 17 ms 33336 KB Output is correct
6 Correct 15 ms 33112 KB Output is correct
7 Correct 14 ms 33116 KB Output is correct
8 Correct 20 ms 33492 KB Output is correct
9 Correct 14 ms 33112 KB Output is correct
10 Correct 13 ms 33212 KB Output is correct
11 Correct 11 ms 33116 KB Output is correct
12 Correct 11 ms 33116 KB Output is correct
13 Correct 12 ms 33116 KB Output is correct
14 Correct 12 ms 33388 KB Output is correct
15 Correct 11 ms 33116 KB Output is correct
16 Correct 11 ms 33116 KB Output is correct
17 Correct 11 ms 33116 KB Output is correct
18 Correct 12 ms 33116 KB Output is correct
19 Correct 12 ms 33116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 33308 KB Output is correct
2 Correct 8 ms 33328 KB Output is correct
3 Correct 10 ms 33116 KB Output is correct
4 Correct 8 ms 33116 KB Output is correct
5 Correct 9 ms 33112 KB Output is correct
6 Correct 9 ms 33112 KB Output is correct
7 Correct 8 ms 33116 KB Output is correct
8 Correct 14 ms 33136 KB Output is correct
9 Correct 12 ms 33116 KB Output is correct
10 Correct 16 ms 33208 KB Output is correct
11 Correct 18 ms 33360 KB Output is correct
12 Correct 15 ms 33156 KB Output is correct
13 Correct 15 ms 33112 KB Output is correct
14 Correct 21 ms 33112 KB Output is correct
15 Correct 17 ms 33336 KB Output is correct
16 Correct 15 ms 33112 KB Output is correct
17 Correct 14 ms 33116 KB Output is correct
18 Correct 20 ms 33492 KB Output is correct
19 Correct 14 ms 33112 KB Output is correct
20 Correct 13 ms 33212 KB Output is correct
21 Correct 11 ms 33116 KB Output is correct
22 Correct 11 ms 33116 KB Output is correct
23 Correct 12 ms 33116 KB Output is correct
24 Correct 12 ms 33388 KB Output is correct
25 Correct 11 ms 33116 KB Output is correct
26 Correct 11 ms 33116 KB Output is correct
27 Correct 11 ms 33116 KB Output is correct
28 Correct 12 ms 33116 KB Output is correct
29 Correct 12 ms 33116 KB Output is correct
30 Correct 14 ms 33112 KB Output is correct
31 Correct 13 ms 33276 KB Output is correct
32 Correct 13 ms 33372 KB Output is correct
33 Correct 12 ms 33368 KB Output is correct
34 Correct 13 ms 33368 KB Output is correct
35 Correct 13 ms 33348 KB Output is correct
36 Correct 12 ms 33372 KB Output is correct
37 Correct 14 ms 33472 KB Output is correct
38 Correct 15 ms 33624 KB Output is correct
39 Correct 14 ms 33628 KB Output is correct
40 Correct 14 ms 34248 KB Output is correct
41 Correct 15 ms 34392 KB Output is correct
42 Correct 13 ms 33372 KB Output is correct
43 Correct 13 ms 33884 KB Output is correct
44 Correct 15 ms 33880 KB Output is correct
45 Correct 14 ms 33884 KB Output is correct
46 Correct 14 ms 33780 KB Output is correct
47 Correct 13 ms 33628 KB Output is correct
48 Correct 13 ms 33624 KB Output is correct
49 Correct 15 ms 33596 KB Output is correct
50 Correct 13 ms 33672 KB Output is correct
51 Correct 13 ms 33512 KB Output is correct
52 Correct 13 ms 33528 KB Output is correct
53 Correct 17 ms 33624 KB Output is correct
54 Correct 17 ms 33628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 33308 KB Output is correct
2 Correct 8 ms 33328 KB Output is correct
3 Correct 10 ms 33116 KB Output is correct
4 Correct 8 ms 33116 KB Output is correct
5 Correct 9 ms 33112 KB Output is correct
6 Correct 9 ms 33112 KB Output is correct
7 Correct 8 ms 33116 KB Output is correct
8 Correct 14 ms 33136 KB Output is correct
9 Correct 12 ms 33116 KB Output is correct
10 Correct 16 ms 33208 KB Output is correct
11 Correct 18 ms 33360 KB Output is correct
12 Correct 15 ms 33156 KB Output is correct
13 Correct 15 ms 33112 KB Output is correct
14 Correct 21 ms 33112 KB Output is correct
15 Correct 17 ms 33336 KB Output is correct
16 Correct 15 ms 33112 KB Output is correct
17 Correct 14 ms 33116 KB Output is correct
18 Correct 20 ms 33492 KB Output is correct
19 Correct 14 ms 33112 KB Output is correct
20 Correct 13 ms 33212 KB Output is correct
21 Correct 11 ms 33116 KB Output is correct
22 Correct 11 ms 33116 KB Output is correct
23 Correct 12 ms 33116 KB Output is correct
24 Correct 12 ms 33388 KB Output is correct
25 Correct 11 ms 33116 KB Output is correct
26 Correct 11 ms 33116 KB Output is correct
27 Correct 11 ms 33116 KB Output is correct
28 Correct 12 ms 33116 KB Output is correct
29 Correct 12 ms 33116 KB Output is correct
30 Correct 14 ms 33112 KB Output is correct
31 Correct 13 ms 33276 KB Output is correct
32 Correct 13 ms 33372 KB Output is correct
33 Correct 12 ms 33368 KB Output is correct
34 Correct 13 ms 33368 KB Output is correct
35 Correct 13 ms 33348 KB Output is correct
36 Correct 12 ms 33372 KB Output is correct
37 Correct 14 ms 33472 KB Output is correct
38 Correct 15 ms 33624 KB Output is correct
39 Correct 14 ms 33628 KB Output is correct
40 Correct 14 ms 34248 KB Output is correct
41 Correct 15 ms 34392 KB Output is correct
42 Correct 13 ms 33372 KB Output is correct
43 Correct 13 ms 33884 KB Output is correct
44 Correct 15 ms 33880 KB Output is correct
45 Correct 14 ms 33884 KB Output is correct
46 Correct 14 ms 33780 KB Output is correct
47 Correct 13 ms 33628 KB Output is correct
48 Correct 13 ms 33624 KB Output is correct
49 Correct 15 ms 33596 KB Output is correct
50 Correct 13 ms 33672 KB Output is correct
51 Correct 13 ms 33512 KB Output is correct
52 Correct 13 ms 33528 KB Output is correct
53 Correct 17 ms 33624 KB Output is correct
54 Correct 17 ms 33628 KB Output is correct
55 Correct 15 ms 34140 KB Output is correct
56 Correct 62 ms 36556 KB Output is correct
57 Correct 70 ms 38740 KB Output is correct
58 Correct 88 ms 40292 KB Output is correct
59 Correct 94 ms 42720 KB Output is correct
60 Correct 121 ms 44832 KB Output is correct
61 Correct 130 ms 47040 KB Output is correct
62 Correct 146 ms 48512 KB Output is correct
63 Correct 225 ms 51144 KB Output is correct
64 Correct 190 ms 51912 KB Output is correct
65 Correct 103 ms 99152 KB Output is correct
66 Correct 115 ms 99156 KB Output is correct
67 Correct 88 ms 47736 KB Output is correct
68 Correct 174 ms 75288 KB Output is correct
69 Correct 197 ms 71512 KB Output is correct
70 Correct 160 ms 71384 KB Output is correct
71 Correct 176 ms 62656 KB Output is correct
72 Correct 174 ms 62912 KB Output is correct
73 Correct 162 ms 59332 KB Output is correct
74 Correct 172 ms 59284 KB Output is correct
75 Correct 173 ms 58044 KB Output is correct
76 Correct 166 ms 58052 KB Output is correct
77 Correct 160 ms 57904 KB Output is correct
78 Correct 155 ms 55944 KB Output is correct
79 Correct 161 ms 56768 KB Output is correct