Submission #349291

# Submission time Handle Problem Language Result Execution time Memory
349291 2021-01-17T10:46:33 Z denkendoemeer Fireworks (APIO16_fireworks) C++14
100 / 100
293 ms 63892 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
priority_queue<ll>pq[300005];
vector<ll>g[300005];
ll sz[300005],cost[300005];
void merg(ll x,ll y)
{
    if (pq[x].size()<pq[y].size())
        swap(pq[x],pq[y]);
    while(!pq[y].empty()){
        pq[x].push(pq[y].top());
        pq[y].pop();
    }
    sz[x]+=sz[y];
}
void dfs(ll nod)
{
    ll x,y,sum=0;
    sz[nod]=cost[nod];
    for(auto &it:g[nod]){
        dfs(it);
        sum++;
        merg(nod,it);
    }
    if (sum==0){
        pq[nod].push(cost[nod]);
        pq[nod].push(cost[nod]);
    }
    else{
        while(sum>1)
            pq[nod].pop(),sum--;
        x=pq[nod].top();
        pq[nod].pop();
        y=pq[nod].top();
        pq[nod].pop();
        pq[nod].push(x+cost[nod]);
        pq[nod].push(y+cost[nod]);
    }
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    ll n,m,x,i;
    scanf("%lld%lld",&n,&m);
    for(i=2;i<=n+m;i++){
        scanf("%lld%lld",&x,&cost[i]);
        g[x].push_back(i);
    }
    dfs(1);
    x=pq[1].top();
    pq[1].pop();
    pq[1].push(0);
    ll num=0,ans=0;
    while(!pq[1].empty()){
        ans=ans+num*(x-pq[1].top());
        x=pq[1].top();
        pq[1].pop();
        num--;
    }
    printf("%lld\n",sz[1]+ans);
return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
fireworks.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         scanf("%lld%lld",&x,&cost[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16748 KB Output is correct
2 Correct 11 ms 16748 KB Output is correct
3 Correct 12 ms 16748 KB Output is correct
4 Correct 13 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 11 ms 16768 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 12 ms 16748 KB Output is correct
10 Correct 11 ms 16876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16748 KB Output is correct
2 Correct 11 ms 16620 KB Output is correct
3 Correct 12 ms 16876 KB Output is correct
4 Correct 11 ms 16748 KB Output is correct
5 Correct 12 ms 16876 KB Output is correct
6 Correct 11 ms 16748 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 12 ms 16748 KB Output is correct
10 Correct 12 ms 16748 KB Output is correct
11 Correct 12 ms 16748 KB Output is correct
12 Correct 13 ms 16748 KB Output is correct
13 Correct 13 ms 16748 KB Output is correct
14 Correct 11 ms 16748 KB Output is correct
15 Correct 12 ms 16748 KB Output is correct
16 Correct 12 ms 16748 KB Output is correct
17 Correct 12 ms 16768 KB Output is correct
18 Correct 12 ms 16748 KB Output is correct
19 Correct 12 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16748 KB Output is correct
2 Correct 11 ms 16748 KB Output is correct
3 Correct 12 ms 16748 KB Output is correct
4 Correct 13 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 11 ms 16768 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 12 ms 16748 KB Output is correct
10 Correct 11 ms 16876 KB Output is correct
11 Correct 12 ms 16748 KB Output is correct
12 Correct 11 ms 16620 KB Output is correct
13 Correct 12 ms 16876 KB Output is correct
14 Correct 11 ms 16748 KB Output is correct
15 Correct 12 ms 16876 KB Output is correct
16 Correct 11 ms 16748 KB Output is correct
17 Correct 11 ms 16748 KB Output is correct
18 Correct 11 ms 16748 KB Output is correct
19 Correct 12 ms 16748 KB Output is correct
20 Correct 12 ms 16748 KB Output is correct
21 Correct 12 ms 16748 KB Output is correct
22 Correct 13 ms 16748 KB Output is correct
23 Correct 13 ms 16748 KB Output is correct
24 Correct 11 ms 16748 KB Output is correct
25 Correct 12 ms 16748 KB Output is correct
26 Correct 12 ms 16748 KB Output is correct
27 Correct 12 ms 16768 KB Output is correct
28 Correct 12 ms 16748 KB Output is correct
29 Correct 12 ms 16748 KB Output is correct
30 Correct 12 ms 16748 KB Output is correct
31 Correct 12 ms 16876 KB Output is correct
32 Correct 13 ms 16876 KB Output is correct
33 Correct 15 ms 16876 KB Output is correct
34 Correct 13 ms 17024 KB Output is correct
35 Correct 14 ms 17004 KB Output is correct
36 Correct 14 ms 17132 KB Output is correct
37 Correct 16 ms 17132 KB Output is correct
38 Correct 15 ms 17132 KB Output is correct
39 Correct 16 ms 17132 KB Output is correct
40 Correct 14 ms 17516 KB Output is correct
41 Correct 14 ms 17536 KB Output is correct
42 Correct 13 ms 17132 KB Output is correct
43 Correct 14 ms 17388 KB Output is correct
44 Correct 14 ms 17260 KB Output is correct
45 Correct 14 ms 17260 KB Output is correct
46 Correct 16 ms 17260 KB Output is correct
47 Correct 15 ms 17388 KB Output is correct
48 Correct 16 ms 17132 KB Output is correct
49 Correct 15 ms 17260 KB Output is correct
50 Correct 15 ms 17132 KB Output is correct
51 Correct 14 ms 17132 KB Output is correct
52 Correct 14 ms 17132 KB Output is correct
53 Correct 15 ms 17260 KB Output is correct
54 Correct 15 ms 17260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16748 KB Output is correct
2 Correct 11 ms 16748 KB Output is correct
3 Correct 12 ms 16748 KB Output is correct
4 Correct 13 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 11 ms 16768 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 12 ms 16748 KB Output is correct
10 Correct 11 ms 16876 KB Output is correct
11 Correct 12 ms 16748 KB Output is correct
12 Correct 11 ms 16620 KB Output is correct
13 Correct 12 ms 16876 KB Output is correct
14 Correct 11 ms 16748 KB Output is correct
15 Correct 12 ms 16876 KB Output is correct
16 Correct 11 ms 16748 KB Output is correct
17 Correct 11 ms 16748 KB Output is correct
18 Correct 11 ms 16748 KB Output is correct
19 Correct 12 ms 16748 KB Output is correct
20 Correct 12 ms 16748 KB Output is correct
21 Correct 12 ms 16748 KB Output is correct
22 Correct 13 ms 16748 KB Output is correct
23 Correct 13 ms 16748 KB Output is correct
24 Correct 11 ms 16748 KB Output is correct
25 Correct 12 ms 16748 KB Output is correct
26 Correct 12 ms 16748 KB Output is correct
27 Correct 12 ms 16768 KB Output is correct
28 Correct 12 ms 16748 KB Output is correct
29 Correct 12 ms 16748 KB Output is correct
30 Correct 12 ms 16748 KB Output is correct
31 Correct 12 ms 16876 KB Output is correct
32 Correct 13 ms 16876 KB Output is correct
33 Correct 15 ms 16876 KB Output is correct
34 Correct 13 ms 17024 KB Output is correct
35 Correct 14 ms 17004 KB Output is correct
36 Correct 14 ms 17132 KB Output is correct
37 Correct 16 ms 17132 KB Output is correct
38 Correct 15 ms 17132 KB Output is correct
39 Correct 16 ms 17132 KB Output is correct
40 Correct 14 ms 17516 KB Output is correct
41 Correct 14 ms 17536 KB Output is correct
42 Correct 13 ms 17132 KB Output is correct
43 Correct 14 ms 17388 KB Output is correct
44 Correct 14 ms 17260 KB Output is correct
45 Correct 14 ms 17260 KB Output is correct
46 Correct 16 ms 17260 KB Output is correct
47 Correct 15 ms 17388 KB Output is correct
48 Correct 16 ms 17132 KB Output is correct
49 Correct 15 ms 17260 KB Output is correct
50 Correct 15 ms 17132 KB Output is correct
51 Correct 14 ms 17132 KB Output is correct
52 Correct 14 ms 17132 KB Output is correct
53 Correct 15 ms 17260 KB Output is correct
54 Correct 15 ms 17260 KB Output is correct
55 Correct 20 ms 17772 KB Output is correct
56 Correct 49 ms 20716 KB Output is correct
57 Correct 85 ms 23404 KB Output is correct
58 Correct 105 ms 25336 KB Output is correct
59 Correct 141 ms 28132 KB Output is correct
60 Correct 179 ms 30948 KB Output is correct
61 Correct 207 ms 33380 KB Output is correct
62 Correct 231 ms 34792 KB Output is correct
63 Correct 285 ms 38368 KB Output is correct
64 Correct 293 ms 39136 KB Output is correct
65 Correct 137 ms 63852 KB Output is correct
66 Correct 142 ms 63892 KB Output is correct
67 Correct 152 ms 35948 KB Output is correct
68 Correct 204 ms 51040 KB Output is correct
69 Correct 235 ms 48996 KB Output is correct
70 Correct 231 ms 48996 KB Output is correct
71 Correct 246 ms 49880 KB Output is correct
72 Correct 243 ms 50140 KB Output is correct
73 Correct 219 ms 46452 KB Output is correct
74 Correct 219 ms 46564 KB Output is correct
75 Correct 224 ms 44888 KB Output is correct
76 Correct 222 ms 44892 KB Output is correct
77 Correct 228 ms 44508 KB Output is correct
78 Correct 228 ms 42728 KB Output is correct
79 Correct 216 ms 43476 KB Output is correct