Submission #464211

# Submission time Handle Problem Language Result Execution time Memory
464211 2021-08-12T13:57:27 Z nonsensenonsense1 Fireworks (APIO16_fireworks) C++17
100 / 100
229 ms 60288 KB
#include <cstdio>
#include <queue>
#include <vector>

const int N = 300000;
int n, m, top[N];
std::vector<int> g[N];

std::pair<std::priority_queue<long long> *, long long> dfs(int v) 
{
	std::pair<std::priority_queue<long long> *, long long> cur;
	if (g[v].empty()) {
		cur.first = new std::priority_queue<long long>;
		cur.first->push(0);
		cur.first->push(0);
	}
	else cur = dfs(g[v][0]);
	for (int i = 1; i < (int)g[v].size(); ++i) {
		std::pair<std::priority_queue<long long> *, long long> s = dfs(g[v][i]);
		if (s.first->size() > cur.first->size()) std::swap(s, cur);
		cur.second += s.second;
		do {
			cur.first->push(s.first->top());
			s.first->pop();
		} while (!s.first->empty());
	}
	for (int i = 0; i < (int)g[v].size() - 1; ++i) {
		cur.second += cur.first->top();
		cur.first->pop();
	}
	long long x = cur.first->top();
	cur.first->pop();
	long long y = cur.first->top();
	cur.first->pop();
	cur.first->push(y + top[v]);
	cur.first->push(x + top[v]);
	cur.second -= top[v];
	return cur;
}

int main() 
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n + m; ++i) {
		int p;
		scanf("%d%d", &p, top + i);
		g[p - 1].push_back(i);
	}
	std::pair<std::priority_queue<long long> *, long long> ans = dfs(0);
	printf("%lld\n", ans.first->top() + ans.second);
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   scanf("%d%d", &p, top + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7328 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 4 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 4 ms 7336 KB Output is correct
8 Correct 6 ms 7244 KB Output is correct
9 Correct 5 ms 7332 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 6 ms 7244 KB Output is correct
4 Correct 4 ms 7336 KB Output is correct
5 Correct 4 ms 7332 KB Output is correct
6 Correct 4 ms 7244 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 5 ms 7244 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7240 KB Output is correct
12 Correct 5 ms 7244 KB Output is correct
13 Correct 5 ms 7340 KB Output is correct
14 Correct 4 ms 7372 KB Output is correct
15 Correct 4 ms 7340 KB Output is correct
16 Correct 4 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 5 ms 7244 KB Output is correct
19 Correct 5 ms 7336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7328 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 4 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 4 ms 7336 KB Output is correct
8 Correct 6 ms 7244 KB Output is correct
9 Correct 5 ms 7332 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 4 ms 7244 KB Output is correct
12 Correct 5 ms 7244 KB Output is correct
13 Correct 6 ms 7244 KB Output is correct
14 Correct 4 ms 7336 KB Output is correct
15 Correct 4 ms 7332 KB Output is correct
16 Correct 4 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 5 ms 7244 KB Output is correct
19 Correct 5 ms 7244 KB Output is correct
20 Correct 5 ms 7244 KB Output is correct
21 Correct 5 ms 7240 KB Output is correct
22 Correct 5 ms 7244 KB Output is correct
23 Correct 5 ms 7340 KB Output is correct
24 Correct 4 ms 7372 KB Output is correct
25 Correct 4 ms 7340 KB Output is correct
26 Correct 4 ms 7244 KB Output is correct
27 Correct 5 ms 7244 KB Output is correct
28 Correct 5 ms 7244 KB Output is correct
29 Correct 5 ms 7336 KB Output is correct
30 Correct 5 ms 7244 KB Output is correct
31 Correct 5 ms 7372 KB Output is correct
32 Correct 5 ms 7352 KB Output is correct
33 Correct 5 ms 7484 KB Output is correct
34 Correct 6 ms 7476 KB Output is correct
35 Correct 6 ms 7628 KB Output is correct
36 Correct 7 ms 7628 KB Output is correct
37 Correct 7 ms 7628 KB Output is correct
38 Correct 7 ms 7732 KB Output is correct
39 Correct 7 ms 7628 KB Output is correct
40 Correct 7 ms 8140 KB Output is correct
41 Correct 6 ms 8140 KB Output is correct
42 Correct 7 ms 7500 KB Output is correct
43 Correct 8 ms 8012 KB Output is correct
44 Correct 8 ms 7884 KB Output is correct
45 Correct 7 ms 7888 KB Output is correct
46 Correct 8 ms 7884 KB Output is correct
47 Correct 8 ms 7884 KB Output is correct
48 Correct 8 ms 7860 KB Output is correct
49 Correct 8 ms 7856 KB Output is correct
50 Correct 7 ms 7756 KB Output is correct
51 Correct 6 ms 7756 KB Output is correct
52 Correct 7 ms 7756 KB Output is correct
53 Correct 7 ms 7884 KB Output is correct
54 Correct 7 ms 7900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7328 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 4 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 4 ms 7336 KB Output is correct
8 Correct 6 ms 7244 KB Output is correct
9 Correct 5 ms 7332 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 4 ms 7244 KB Output is correct
12 Correct 5 ms 7244 KB Output is correct
13 Correct 6 ms 7244 KB Output is correct
14 Correct 4 ms 7336 KB Output is correct
15 Correct 4 ms 7332 KB Output is correct
16 Correct 4 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 5 ms 7244 KB Output is correct
19 Correct 5 ms 7244 KB Output is correct
20 Correct 5 ms 7244 KB Output is correct
21 Correct 5 ms 7240 KB Output is correct
22 Correct 5 ms 7244 KB Output is correct
23 Correct 5 ms 7340 KB Output is correct
24 Correct 4 ms 7372 KB Output is correct
25 Correct 4 ms 7340 KB Output is correct
26 Correct 4 ms 7244 KB Output is correct
27 Correct 5 ms 7244 KB Output is correct
28 Correct 5 ms 7244 KB Output is correct
29 Correct 5 ms 7336 KB Output is correct
30 Correct 5 ms 7244 KB Output is correct
31 Correct 5 ms 7372 KB Output is correct
32 Correct 5 ms 7352 KB Output is correct
33 Correct 5 ms 7484 KB Output is correct
34 Correct 6 ms 7476 KB Output is correct
35 Correct 6 ms 7628 KB Output is correct
36 Correct 7 ms 7628 KB Output is correct
37 Correct 7 ms 7628 KB Output is correct
38 Correct 7 ms 7732 KB Output is correct
39 Correct 7 ms 7628 KB Output is correct
40 Correct 7 ms 8140 KB Output is correct
41 Correct 6 ms 8140 KB Output is correct
42 Correct 7 ms 7500 KB Output is correct
43 Correct 8 ms 8012 KB Output is correct
44 Correct 8 ms 7884 KB Output is correct
45 Correct 7 ms 7888 KB Output is correct
46 Correct 8 ms 7884 KB Output is correct
47 Correct 8 ms 7884 KB Output is correct
48 Correct 8 ms 7860 KB Output is correct
49 Correct 8 ms 7856 KB Output is correct
50 Correct 7 ms 7756 KB Output is correct
51 Correct 6 ms 7756 KB Output is correct
52 Correct 7 ms 7756 KB Output is correct
53 Correct 7 ms 7884 KB Output is correct
54 Correct 7 ms 7900 KB Output is correct
55 Correct 14 ms 8388 KB Output is correct
56 Correct 34 ms 11440 KB Output is correct
57 Correct 63 ms 14312 KB Output is correct
58 Correct 79 ms 16248 KB Output is correct
59 Correct 103 ms 19212 KB Output is correct
60 Correct 135 ms 22168 KB Output is correct
61 Correct 163 ms 24460 KB Output is correct
62 Correct 189 ms 26064 KB Output is correct
63 Correct 219 ms 29848 KB Output is correct
64 Correct 229 ms 30888 KB Output is correct
65 Correct 128 ms 60288 KB Output is correct
66 Correct 146 ms 60228 KB Output is correct
67 Correct 122 ms 22812 KB Output is correct
68 Correct 185 ms 49740 KB Output is correct
69 Correct 205 ms 46536 KB Output is correct
70 Correct 212 ms 46704 KB Output is correct
71 Correct 213 ms 49160 KB Output is correct
72 Correct 212 ms 48968 KB Output is correct
73 Correct 210 ms 45740 KB Output is correct
74 Correct 184 ms 45872 KB Output is correct
75 Correct 189 ms 44592 KB Output is correct
76 Correct 193 ms 44764 KB Output is correct
77 Correct 197 ms 43348 KB Output is correct
78 Correct 197 ms 42180 KB Output is correct
79 Correct 190 ms 41816 KB Output is correct