Submission #99955

# Submission time Handle Problem Language Result Execution time Memory
99955 2019-03-08T22:25:50 Z TadijaSebez Fireworks (APIO16_fireworks) C++11
100 / 100
192 ms 30184 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=300050;
priority_queue<ll> pq[N];
int par[N],len[N],deg[N];
ll dp[N];
int main()
{
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=2;i<=n+m;i++)
	{
		scanf("%i %i",&par[i],&len[i]);
		deg[par[i]]++;
		if(i>n)
		{
			dp[par[i]]-=len[i];
			pq[par[i]].push(len[i]);
			pq[par[i]].push(len[i]);
		}
	}
	for(int i=n;i>=2;i--)
	{
		for(int j=1;j<=deg[i]-1;j++)
		{
			dp[i]+=pq[i].top();
			pq[i].pop();
		}
		ll x=pq[i].top();
		pq[i].pop();
		ll y=pq[i].top();
		pq[i].pop();
		pq[i].push(x+len[i]);
		pq[i].push(y+len[i]);
		dp[i]-=len[i];
		dp[par[i]]+=dp[i];
		if(pq[par[i]].size()<pq[i].size()) pq[par[i]].swap(pq[i]);
		while(pq[i].size()) pq[par[i]].push(pq[i].top()),pq[i].pop();
	}
	ll ans=dp[1];
	for(int j=1;j<=deg[1];j++) ans+=pq[1].top(),pq[1].pop();
	printf("%lld\n",ans);
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
fireworks.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&par[i],&len[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 10 ms 9728 KB Output is correct
3 Correct 10 ms 9728 KB Output is correct
4 Correct 10 ms 9728 KB Output is correct
5 Correct 11 ms 9728 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Correct 11 ms 9728 KB Output is correct
8 Correct 11 ms 9728 KB Output is correct
9 Correct 10 ms 9728 KB Output is correct
10 Correct 10 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 11 ms 9744 KB Output is correct
3 Correct 10 ms 9728 KB Output is correct
4 Correct 10 ms 9728 KB Output is correct
5 Correct 11 ms 9728 KB Output is correct
6 Correct 12 ms 9728 KB Output is correct
7 Correct 11 ms 9856 KB Output is correct
8 Correct 11 ms 9728 KB Output is correct
9 Correct 11 ms 9728 KB Output is correct
10 Correct 10 ms 9728 KB Output is correct
11 Correct 11 ms 9728 KB Output is correct
12 Correct 10 ms 9856 KB Output is correct
13 Correct 11 ms 9728 KB Output is correct
14 Correct 10 ms 9728 KB Output is correct
15 Correct 11 ms 9728 KB Output is correct
16 Correct 12 ms 9728 KB Output is correct
17 Correct 11 ms 9728 KB Output is correct
18 Correct 11 ms 9856 KB Output is correct
19 Correct 11 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 10 ms 9728 KB Output is correct
3 Correct 10 ms 9728 KB Output is correct
4 Correct 10 ms 9728 KB Output is correct
5 Correct 11 ms 9728 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Correct 11 ms 9728 KB Output is correct
8 Correct 11 ms 9728 KB Output is correct
9 Correct 10 ms 9728 KB Output is correct
10 Correct 10 ms 9728 KB Output is correct
11 Correct 10 ms 9728 KB Output is correct
12 Correct 11 ms 9744 KB Output is correct
13 Correct 10 ms 9728 KB Output is correct
14 Correct 10 ms 9728 KB Output is correct
15 Correct 11 ms 9728 KB Output is correct
16 Correct 12 ms 9728 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 11 ms 9728 KB Output is correct
19 Correct 11 ms 9728 KB Output is correct
20 Correct 10 ms 9728 KB Output is correct
21 Correct 11 ms 9728 KB Output is correct
22 Correct 10 ms 9856 KB Output is correct
23 Correct 11 ms 9728 KB Output is correct
24 Correct 10 ms 9728 KB Output is correct
25 Correct 11 ms 9728 KB Output is correct
26 Correct 12 ms 9728 KB Output is correct
27 Correct 11 ms 9728 KB Output is correct
28 Correct 11 ms 9856 KB Output is correct
29 Correct 11 ms 9856 KB Output is correct
30 Correct 13 ms 9856 KB Output is correct
31 Correct 13 ms 9856 KB Output is correct
32 Correct 14 ms 9856 KB Output is correct
33 Correct 15 ms 9856 KB Output is correct
34 Correct 12 ms 9856 KB Output is correct
35 Correct 14 ms 9984 KB Output is correct
36 Correct 14 ms 9984 KB Output is correct
37 Correct 14 ms 9984 KB Output is correct
38 Correct 12 ms 9984 KB Output is correct
39 Correct 13 ms 9984 KB Output is correct
40 Correct 12 ms 9856 KB Output is correct
41 Correct 12 ms 9984 KB Output is correct
42 Correct 13 ms 9856 KB Output is correct
43 Correct 14 ms 9984 KB Output is correct
44 Correct 15 ms 9984 KB Output is correct
45 Correct 13 ms 10112 KB Output is correct
46 Correct 16 ms 10112 KB Output is correct
47 Correct 35 ms 10104 KB Output is correct
48 Correct 13 ms 9984 KB Output is correct
49 Correct 13 ms 10112 KB Output is correct
50 Correct 13 ms 9984 KB Output is correct
51 Correct 16 ms 9984 KB Output is correct
52 Correct 13 ms 10108 KB Output is correct
53 Correct 13 ms 9984 KB Output is correct
54 Correct 14 ms 10112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 10 ms 9728 KB Output is correct
3 Correct 10 ms 9728 KB Output is correct
4 Correct 10 ms 9728 KB Output is correct
5 Correct 11 ms 9728 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Correct 11 ms 9728 KB Output is correct
8 Correct 11 ms 9728 KB Output is correct
9 Correct 10 ms 9728 KB Output is correct
10 Correct 10 ms 9728 KB Output is correct
11 Correct 10 ms 9728 KB Output is correct
12 Correct 11 ms 9744 KB Output is correct
13 Correct 10 ms 9728 KB Output is correct
14 Correct 10 ms 9728 KB Output is correct
15 Correct 11 ms 9728 KB Output is correct
16 Correct 12 ms 9728 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 11 ms 9728 KB Output is correct
19 Correct 11 ms 9728 KB Output is correct
20 Correct 10 ms 9728 KB Output is correct
21 Correct 11 ms 9728 KB Output is correct
22 Correct 10 ms 9856 KB Output is correct
23 Correct 11 ms 9728 KB Output is correct
24 Correct 10 ms 9728 KB Output is correct
25 Correct 11 ms 9728 KB Output is correct
26 Correct 12 ms 9728 KB Output is correct
27 Correct 11 ms 9728 KB Output is correct
28 Correct 11 ms 9856 KB Output is correct
29 Correct 11 ms 9856 KB Output is correct
30 Correct 13 ms 9856 KB Output is correct
31 Correct 13 ms 9856 KB Output is correct
32 Correct 14 ms 9856 KB Output is correct
33 Correct 15 ms 9856 KB Output is correct
34 Correct 12 ms 9856 KB Output is correct
35 Correct 14 ms 9984 KB Output is correct
36 Correct 14 ms 9984 KB Output is correct
37 Correct 14 ms 9984 KB Output is correct
38 Correct 12 ms 9984 KB Output is correct
39 Correct 13 ms 9984 KB Output is correct
40 Correct 12 ms 9856 KB Output is correct
41 Correct 12 ms 9984 KB Output is correct
42 Correct 13 ms 9856 KB Output is correct
43 Correct 14 ms 9984 KB Output is correct
44 Correct 15 ms 9984 KB Output is correct
45 Correct 13 ms 10112 KB Output is correct
46 Correct 16 ms 10112 KB Output is correct
47 Correct 35 ms 10104 KB Output is correct
48 Correct 13 ms 9984 KB Output is correct
49 Correct 13 ms 10112 KB Output is correct
50 Correct 13 ms 9984 KB Output is correct
51 Correct 16 ms 9984 KB Output is correct
52 Correct 13 ms 10108 KB Output is correct
53 Correct 13 ms 9984 KB Output is correct
54 Correct 14 ms 10112 KB Output is correct
55 Correct 19 ms 10624 KB Output is correct
56 Correct 39 ms 13020 KB Output is correct
57 Correct 60 ms 15224 KB Output is correct
58 Correct 81 ms 16948 KB Output is correct
59 Correct 103 ms 19144 KB Output is correct
60 Correct 117 ms 21484 KB Output is correct
61 Correct 122 ms 23408 KB Output is correct
62 Correct 137 ms 24664 KB Output is correct
63 Correct 165 ms 27436 KB Output is correct
64 Correct 192 ms 28116 KB Output is correct
65 Correct 89 ms 20476 KB Output is correct
66 Correct 98 ms 20536 KB Output is correct
67 Correct 130 ms 20660 KB Output is correct
68 Correct 156 ms 25400 KB Output is correct
69 Correct 172 ms 25324 KB Output is correct
70 Correct 181 ms 25452 KB Output is correct
71 Correct 185 ms 30060 KB Output is correct
72 Correct 170 ms 30184 KB Output is correct
73 Correct 153 ms 26472 KB Output is correct
74 Correct 168 ms 27036 KB Output is correct
75 Correct 143 ms 25572 KB Output is correct
76 Correct 137 ms 25572 KB Output is correct
77 Correct 157 ms 25888 KB Output is correct
78 Correct 152 ms 25472 KB Output is correct
79 Correct 146 ms 23368 KB Output is correct