Submission #1067002

# Submission time Handle Problem Language Result Execution time Memory
1067002 2024-08-20T09:32:01 Z vjudge1 Fireworks (APIO16_fireworks) C++17
100 / 100
316 ms 56912 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define ll long long
#define N 300005
#define endl "\n" 
#define fi first
#define se second
using namespace std;

const ll mod=1e9+7;
const ll inf=1e18;
const double eps=1e-6;
__gnu_pbds::priority_queue<ll> q[N];
ll n,m,w[N],d[N],res=0;
vector<ll>v[N];

void dfs(ll x){
    ll l=0,r=0;
    for(auto y:v[x]){
        dfs(y);
        q[x].join(q[y]);
    }
    if(x<=n){
        for(int i=1;i<d[x];i++)q[x].pop();
        l=q[x].top();q[x].pop();
        r=q[x].top();q[x].pop();
    }
    q[x].push(l+w[x]);
    q[x].push(r+w[x]);
}
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin>>n>>m;
    for(int i=2,x;i<=n+m;i++){
        cin>>x>>w[i];
        res+=w[i],d[x]++;
        v[x].push_back(i);
    }
    dfs(1);
    q[1].pop();
    ll now=1;
    while(!q[1].empty()){
        res-=q[1].top();
        q[1].pop();
    }
    cout<<res<<endl;
    return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:43:8: warning: unused variable 'now' [-Wunused-variable]
   43 |     ll now=1;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 6 ms 14500 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14324 KB Output is correct
6 Correct 6 ms 14424 KB Output is correct
7 Correct 7 ms 14428 KB Output is correct
8 Correct 7 ms 14680 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 6 ms 14544 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14424 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 6 ms 14428 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14368 KB Output is correct
19 Correct 8 ms 14356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 6 ms 14500 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14324 KB Output is correct
6 Correct 6 ms 14424 KB Output is correct
7 Correct 7 ms 14428 KB Output is correct
8 Correct 7 ms 14680 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 6 ms 14544 KB Output is correct
14 Correct 7 ms 14428 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14428 KB Output is correct
19 Correct 6 ms 14428 KB Output is correct
20 Correct 6 ms 14428 KB Output is correct
21 Correct 6 ms 14424 KB Output is correct
22 Correct 6 ms 14428 KB Output is correct
23 Correct 6 ms 14428 KB Output is correct
24 Correct 6 ms 14428 KB Output is correct
25 Correct 6 ms 14428 KB Output is correct
26 Correct 6 ms 14428 KB Output is correct
27 Correct 6 ms 14428 KB Output is correct
28 Correct 6 ms 14368 KB Output is correct
29 Correct 8 ms 14356 KB Output is correct
30 Correct 6 ms 14428 KB Output is correct
31 Correct 7 ms 14424 KB Output is correct
32 Correct 7 ms 14428 KB Output is correct
33 Correct 8 ms 14668 KB Output is correct
34 Correct 8 ms 14636 KB Output is correct
35 Correct 8 ms 14680 KB Output is correct
36 Correct 8 ms 14684 KB Output is correct
37 Correct 9 ms 14680 KB Output is correct
38 Correct 8 ms 14684 KB Output is correct
39 Correct 9 ms 14684 KB Output is correct
40 Correct 9 ms 15196 KB Output is correct
41 Correct 10 ms 15196 KB Output is correct
42 Correct 9 ms 14684 KB Output is correct
43 Correct 9 ms 14936 KB Output is correct
44 Correct 9 ms 14940 KB Output is correct
45 Correct 9 ms 15016 KB Output is correct
46 Correct 9 ms 14936 KB Output is correct
47 Correct 9 ms 14936 KB Output is correct
48 Correct 14 ms 14684 KB Output is correct
49 Correct 9 ms 14940 KB Output is correct
50 Correct 10 ms 14940 KB Output is correct
51 Correct 10 ms 14936 KB Output is correct
52 Correct 9 ms 14936 KB Output is correct
53 Correct 9 ms 14932 KB Output is correct
54 Correct 10 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 6 ms 14500 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14324 KB Output is correct
6 Correct 6 ms 14424 KB Output is correct
7 Correct 7 ms 14428 KB Output is correct
8 Correct 7 ms 14680 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 6 ms 14544 KB Output is correct
14 Correct 7 ms 14428 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14428 KB Output is correct
19 Correct 6 ms 14428 KB Output is correct
20 Correct 6 ms 14428 KB Output is correct
21 Correct 6 ms 14424 KB Output is correct
22 Correct 6 ms 14428 KB Output is correct
23 Correct 6 ms 14428 KB Output is correct
24 Correct 6 ms 14428 KB Output is correct
25 Correct 6 ms 14428 KB Output is correct
26 Correct 6 ms 14428 KB Output is correct
27 Correct 6 ms 14428 KB Output is correct
28 Correct 6 ms 14368 KB Output is correct
29 Correct 8 ms 14356 KB Output is correct
30 Correct 6 ms 14428 KB Output is correct
31 Correct 7 ms 14424 KB Output is correct
32 Correct 7 ms 14428 KB Output is correct
33 Correct 8 ms 14668 KB Output is correct
34 Correct 8 ms 14636 KB Output is correct
35 Correct 8 ms 14680 KB Output is correct
36 Correct 8 ms 14684 KB Output is correct
37 Correct 9 ms 14680 KB Output is correct
38 Correct 8 ms 14684 KB Output is correct
39 Correct 9 ms 14684 KB Output is correct
40 Correct 9 ms 15196 KB Output is correct
41 Correct 10 ms 15196 KB Output is correct
42 Correct 9 ms 14684 KB Output is correct
43 Correct 9 ms 14936 KB Output is correct
44 Correct 9 ms 14940 KB Output is correct
45 Correct 9 ms 15016 KB Output is correct
46 Correct 9 ms 14936 KB Output is correct
47 Correct 9 ms 14936 KB Output is correct
48 Correct 14 ms 14684 KB Output is correct
49 Correct 9 ms 14940 KB Output is correct
50 Correct 10 ms 14940 KB Output is correct
51 Correct 10 ms 14936 KB Output is correct
52 Correct 9 ms 14936 KB Output is correct
53 Correct 9 ms 14932 KB Output is correct
54 Correct 10 ms 14940 KB Output is correct
55 Correct 13 ms 15196 KB Output is correct
56 Correct 37 ms 17568 KB Output is correct
57 Correct 71 ms 19948 KB Output is correct
58 Correct 81 ms 21668 KB Output is correct
59 Correct 104 ms 23892 KB Output is correct
60 Correct 127 ms 26472 KB Output is correct
61 Correct 161 ms 27988 KB Output is correct
62 Correct 164 ms 29520 KB Output is correct
63 Correct 197 ms 32336 KB Output is correct
64 Correct 225 ms 33360 KB Output is correct
65 Correct 197 ms 56912 KB Output is correct
66 Correct 174 ms 56844 KB Output is correct
67 Correct 195 ms 33380 KB Output is correct
68 Correct 230 ms 46104 KB Output is correct
69 Correct 223 ms 45204 KB Output is correct
70 Correct 213 ms 44884 KB Output is correct
71 Correct 232 ms 38480 KB Output is correct
72 Correct 243 ms 38484 KB Output is correct
73 Correct 245 ms 37972 KB Output is correct
74 Correct 232 ms 37968 KB Output is correct
75 Correct 237 ms 37460 KB Output is correct
76 Correct 262 ms 37692 KB Output is correct
77 Correct 269 ms 37324 KB Output is correct
78 Correct 267 ms 37956 KB Output is correct
79 Correct 316 ms 50696 KB Output is correct