답안 #135165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135165 2019-07-23T17:38:03 Z sebinkim Fireworks (APIO16_fireworks) C++14
100 / 100
371 ms 59740 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

priority_queue <ll> P[303030];
vector <ll> V[303030];
ll S[303030], C[303030];
ll n, m, ans;

void merge(ll p, ll q)
{
	if(P[p].size() < P[q].size()) swap(P[p], P[q]);
	for(; !P[q].empty(); P[q].pop()) P[p].push(P[q].top());
	S[p] += S[q];
}

void dfs(ll p)
{
	ll x, y, s = 0;
	
	S[p] = C[p];
	
	for(ll &t: V[p]){
		dfs(t); s ++;
		merge(p, t);
	}
	
	if(s == 0){
		P[p].push(C[p]); P[p].push(C[p]);
	}
	else{
		for(; s>1; s--) P[p].pop();
		x = P[p].top(); P[p].pop();
		y = P[p].top(); P[p].pop();
		P[p].push(x + C[p]); P[p].push(y + C[p]);
	}
}

int main()
{
	ll i, p, x;
	
	scanf("%lld%lld", &n, &m);
	
	for(i=2; i<=n+m; i++){
		scanf("%lld%lld", &p, C + i);
		V[p].push_back(i);
	}
	
	dfs(1);
	
	x = P[1].top(); P[1].pop();
	P[1].push(0);
	
	for(i=0; !P[1].empty(); i--){
		ans += i * (x - P[1].top());
		x = P[1].top(); P[1].pop();
	}
	
	printf("%lld\n", S[1] + ans);
	
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
fireworks.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &p, C + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16888 KB Output is correct
2 Correct 17 ms 16888 KB Output is correct
3 Correct 17 ms 16888 KB Output is correct
4 Correct 17 ms 16888 KB Output is correct
5 Correct 16 ms 16888 KB Output is correct
6 Correct 17 ms 17016 KB Output is correct
7 Correct 17 ms 16888 KB Output is correct
8 Correct 17 ms 16888 KB Output is correct
9 Correct 17 ms 16888 KB Output is correct
10 Correct 17 ms 17016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16888 KB Output is correct
2 Correct 17 ms 16888 KB Output is correct
3 Correct 17 ms 17016 KB Output is correct
4 Correct 18 ms 17016 KB Output is correct
5 Correct 17 ms 16972 KB Output is correct
6 Correct 18 ms 16980 KB Output is correct
7 Correct 17 ms 16888 KB Output is correct
8 Correct 17 ms 17020 KB Output is correct
9 Correct 21 ms 16888 KB Output is correct
10 Correct 17 ms 16892 KB Output is correct
11 Correct 17 ms 16888 KB Output is correct
12 Correct 16 ms 16888 KB Output is correct
13 Correct 17 ms 16888 KB Output is correct
14 Correct 17 ms 17016 KB Output is correct
15 Correct 16 ms 17016 KB Output is correct
16 Correct 18 ms 16888 KB Output is correct
17 Correct 17 ms 17016 KB Output is correct
18 Correct 17 ms 17016 KB Output is correct
19 Correct 17 ms 17016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16888 KB Output is correct
2 Correct 17 ms 16888 KB Output is correct
3 Correct 17 ms 16888 KB Output is correct
4 Correct 17 ms 16888 KB Output is correct
5 Correct 16 ms 16888 KB Output is correct
6 Correct 17 ms 17016 KB Output is correct
7 Correct 17 ms 16888 KB Output is correct
8 Correct 17 ms 16888 KB Output is correct
9 Correct 17 ms 16888 KB Output is correct
10 Correct 17 ms 17016 KB Output is correct
11 Correct 17 ms 16888 KB Output is correct
12 Correct 17 ms 16888 KB Output is correct
13 Correct 17 ms 17016 KB Output is correct
14 Correct 18 ms 17016 KB Output is correct
15 Correct 17 ms 16972 KB Output is correct
16 Correct 18 ms 16980 KB Output is correct
17 Correct 17 ms 16888 KB Output is correct
18 Correct 17 ms 17020 KB Output is correct
19 Correct 21 ms 16888 KB Output is correct
20 Correct 17 ms 16892 KB Output is correct
21 Correct 17 ms 16888 KB Output is correct
22 Correct 16 ms 16888 KB Output is correct
23 Correct 17 ms 16888 KB Output is correct
24 Correct 17 ms 17016 KB Output is correct
25 Correct 16 ms 17016 KB Output is correct
26 Correct 18 ms 16888 KB Output is correct
27 Correct 17 ms 17016 KB Output is correct
28 Correct 17 ms 17016 KB Output is correct
29 Correct 17 ms 17016 KB Output is correct
30 Correct 19 ms 17016 KB Output is correct
31 Correct 17 ms 17016 KB Output is correct
32 Correct 18 ms 17016 KB Output is correct
33 Correct 18 ms 17144 KB Output is correct
34 Correct 19 ms 17144 KB Output is correct
35 Correct 20 ms 17144 KB Output is correct
36 Correct 19 ms 17272 KB Output is correct
37 Correct 21 ms 17272 KB Output is correct
38 Correct 21 ms 17272 KB Output is correct
39 Correct 21 ms 17272 KB Output is correct
40 Correct 19 ms 17656 KB Output is correct
41 Correct 20 ms 17656 KB Output is correct
42 Correct 19 ms 17272 KB Output is correct
43 Correct 21 ms 17528 KB Output is correct
44 Correct 21 ms 17400 KB Output is correct
45 Correct 21 ms 17400 KB Output is correct
46 Correct 21 ms 17400 KB Output is correct
47 Correct 21 ms 17400 KB Output is correct
48 Correct 24 ms 17272 KB Output is correct
49 Correct 25 ms 17400 KB Output is correct
50 Correct 20 ms 17276 KB Output is correct
51 Correct 24 ms 17272 KB Output is correct
52 Correct 20 ms 17272 KB Output is correct
53 Correct 20 ms 17404 KB Output is correct
54 Correct 20 ms 17400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16888 KB Output is correct
2 Correct 17 ms 16888 KB Output is correct
3 Correct 17 ms 16888 KB Output is correct
4 Correct 17 ms 16888 KB Output is correct
5 Correct 16 ms 16888 KB Output is correct
6 Correct 17 ms 17016 KB Output is correct
7 Correct 17 ms 16888 KB Output is correct
8 Correct 17 ms 16888 KB Output is correct
9 Correct 17 ms 16888 KB Output is correct
10 Correct 17 ms 17016 KB Output is correct
11 Correct 17 ms 16888 KB Output is correct
12 Correct 17 ms 16888 KB Output is correct
13 Correct 17 ms 17016 KB Output is correct
14 Correct 18 ms 17016 KB Output is correct
15 Correct 17 ms 16972 KB Output is correct
16 Correct 18 ms 16980 KB Output is correct
17 Correct 17 ms 16888 KB Output is correct
18 Correct 17 ms 17020 KB Output is correct
19 Correct 21 ms 16888 KB Output is correct
20 Correct 17 ms 16892 KB Output is correct
21 Correct 17 ms 16888 KB Output is correct
22 Correct 16 ms 16888 KB Output is correct
23 Correct 17 ms 16888 KB Output is correct
24 Correct 17 ms 17016 KB Output is correct
25 Correct 16 ms 17016 KB Output is correct
26 Correct 18 ms 16888 KB Output is correct
27 Correct 17 ms 17016 KB Output is correct
28 Correct 17 ms 17016 KB Output is correct
29 Correct 17 ms 17016 KB Output is correct
30 Correct 19 ms 17016 KB Output is correct
31 Correct 17 ms 17016 KB Output is correct
32 Correct 18 ms 17016 KB Output is correct
33 Correct 18 ms 17144 KB Output is correct
34 Correct 19 ms 17144 KB Output is correct
35 Correct 20 ms 17144 KB Output is correct
36 Correct 19 ms 17272 KB Output is correct
37 Correct 21 ms 17272 KB Output is correct
38 Correct 21 ms 17272 KB Output is correct
39 Correct 21 ms 17272 KB Output is correct
40 Correct 19 ms 17656 KB Output is correct
41 Correct 20 ms 17656 KB Output is correct
42 Correct 19 ms 17272 KB Output is correct
43 Correct 21 ms 17528 KB Output is correct
44 Correct 21 ms 17400 KB Output is correct
45 Correct 21 ms 17400 KB Output is correct
46 Correct 21 ms 17400 KB Output is correct
47 Correct 21 ms 17400 KB Output is correct
48 Correct 24 ms 17272 KB Output is correct
49 Correct 25 ms 17400 KB Output is correct
50 Correct 20 ms 17276 KB Output is correct
51 Correct 24 ms 17272 KB Output is correct
52 Correct 20 ms 17272 KB Output is correct
53 Correct 20 ms 17404 KB Output is correct
54 Correct 20 ms 17400 KB Output is correct
55 Correct 28 ms 18040 KB Output is correct
56 Correct 60 ms 20676 KB Output is correct
57 Correct 96 ms 22896 KB Output is correct
58 Correct 123 ms 24432 KB Output is correct
59 Correct 168 ms 26604 KB Output is correct
60 Correct 210 ms 28912 KB Output is correct
61 Correct 235 ms 30732 KB Output is correct
62 Correct 265 ms 32112 KB Output is correct
63 Correct 371 ms 34668 KB Output is correct
64 Correct 329 ms 35440 KB Output is correct
65 Correct 159 ms 59740 KB Output is correct
66 Correct 158 ms 59740 KB Output is correct
67 Correct 194 ms 31608 KB Output is correct
68 Correct 235 ms 47020 KB Output is correct
69 Correct 281 ms 44904 KB Output is correct
70 Correct 313 ms 45108 KB Output is correct
71 Correct 290 ms 46560 KB Output is correct
72 Correct 299 ms 46724 KB Output is correct
73 Correct 258 ms 42972 KB Output is correct
74 Correct 260 ms 43176 KB Output is correct
75 Correct 260 ms 41692 KB Output is correct
76 Correct 260 ms 41836 KB Output is correct
77 Correct 262 ms 41064 KB Output is correct
78 Correct 265 ms 39268 KB Output is correct
79 Correct 261 ms 40644 KB Output is correct