# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47690 | 2018-05-06T09:48:57 Z | E869120 | Fireworks (APIO16_fireworks) | C++14 | 2000 ms | 373772 KB |
#include <iostream> #include <vector> #include <algorithm> using namespace std; #pragma warning (disable: 4996) long long N, M, A[300009], B[300009], dist[300009], sum; vector<pair<long long, long long>>x[300009]; vector<long long>G[300009]; void dfs1(int pos, long long depth) { dist[pos] = depth; for (int i = 0; i < x[pos].size(); i++) dfs1(x[pos][i].first, depth + x[pos][i].second); } void dfs2(int pos) { if (x[pos].size() == 0) { G[pos].push_back(dist[pos]); G[pos].push_back(dist[pos]); return; } for (int i = 0; i < x[pos].size(); i++) dfs2(x[pos][i].first); for (int i = 0; i < x[pos].size(); i++) { for (int j = 0; j < G[x[pos][i].first].size(); j++) G[pos].push_back(G[x[pos][i].first][j]); } sort(G[pos].begin(), G[pos].end()); vector<long long>H; for (int i = 0; i < (int)G[pos].size() - (int)x[pos].size() + 1; i++) H.push_back(G[pos][i]); G[pos] = H; for (int i = 0; i < (int)G[pos].size() - 2; i++) G[pos][i] -= B[pos]; } int main() { cin >> N >> M; for (int i = 2; i <= N + M; i++) { scanf("%lld%lld", &A[i], &B[i]); sum += B[i]; x[A[i]].push_back(make_pair(i, B[i])); } dfs1(1, 0); dfs2(1); long long ret = sum, cx = 0, D = G[1].size() - 1; for (int i = 0; i < G[1].size() - 1; i++) { ret -= (G[1][i] - cx)*D; cx = G[1][i]; D--; } cout << ret << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 14456 KB | Output is correct |
2 | Correct | 12 ms | 14456 KB | Output is correct |
3 | Correct | 13 ms | 14536 KB | Output is correct |
4 | Correct | 13 ms | 14536 KB | Output is correct |
5 | Correct | 13 ms | 14692 KB | Output is correct |
6 | Correct | 13 ms | 14692 KB | Output is correct |
7 | Correct | 13 ms | 14692 KB | Output is correct |
8 | Correct | 13 ms | 14756 KB | Output is correct |
9 | Correct | 13 ms | 14756 KB | Output is correct |
10 | Correct | 13 ms | 14756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 14756 KB | Output is correct |
2 | Correct | 13 ms | 14756 KB | Output is correct |
3 | Correct | 13 ms | 14756 KB | Output is correct |
4 | Correct | 13 ms | 14756 KB | Output is correct |
5 | Correct | 13 ms | 14756 KB | Output is correct |
6 | Correct | 13 ms | 14772 KB | Output is correct |
7 | Correct | 13 ms | 14776 KB | Output is correct |
8 | Correct | 13 ms | 14780 KB | Output is correct |
9 | Correct | 13 ms | 14912 KB | Output is correct |
10 | Correct | 13 ms | 14912 KB | Output is correct |
11 | Correct | 13 ms | 14912 KB | Output is correct |
12 | Correct | 13 ms | 14912 KB | Output is correct |
13 | Correct | 13 ms | 14912 KB | Output is correct |
14 | Correct | 13 ms | 14912 KB | Output is correct |
15 | Correct | 13 ms | 14912 KB | Output is correct |
16 | Correct | 13 ms | 14912 KB | Output is correct |
17 | Correct | 14 ms | 14912 KB | Output is correct |
18 | Correct | 13 ms | 14912 KB | Output is correct |
19 | Correct | 16 ms | 14912 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 14456 KB | Output is correct |
2 | Correct | 12 ms | 14456 KB | Output is correct |
3 | Correct | 13 ms | 14536 KB | Output is correct |
4 | Correct | 13 ms | 14536 KB | Output is correct |
5 | Correct | 13 ms | 14692 KB | Output is correct |
6 | Correct | 13 ms | 14692 KB | Output is correct |
7 | Correct | 13 ms | 14692 KB | Output is correct |
8 | Correct | 13 ms | 14756 KB | Output is correct |
9 | Correct | 13 ms | 14756 KB | Output is correct |
10 | Correct | 13 ms | 14756 KB | Output is correct |
11 | Correct | 12 ms | 14756 KB | Output is correct |
12 | Correct | 13 ms | 14756 KB | Output is correct |
13 | Correct | 13 ms | 14756 KB | Output is correct |
14 | Correct | 13 ms | 14756 KB | Output is correct |
15 | Correct | 13 ms | 14756 KB | Output is correct |
16 | Correct | 13 ms | 14772 KB | Output is correct |
17 | Correct | 13 ms | 14776 KB | Output is correct |
18 | Correct | 13 ms | 14780 KB | Output is correct |
19 | Correct | 13 ms | 14912 KB | Output is correct |
20 | Correct | 13 ms | 14912 KB | Output is correct |
21 | Correct | 13 ms | 14912 KB | Output is correct |
22 | Correct | 13 ms | 14912 KB | Output is correct |
23 | Correct | 13 ms | 14912 KB | Output is correct |
24 | Correct | 13 ms | 14912 KB | Output is correct |
25 | Correct | 13 ms | 14912 KB | Output is correct |
26 | Correct | 13 ms | 14912 KB | Output is correct |
27 | Correct | 14 ms | 14912 KB | Output is correct |
28 | Correct | 13 ms | 14912 KB | Output is correct |
29 | Correct | 16 ms | 14912 KB | Output is correct |
30 | Correct | 14 ms | 14976 KB | Output is correct |
31 | Correct | 15 ms | 15368 KB | Output is correct |
32 | Correct | 18 ms | 15432 KB | Output is correct |
33 | Correct | 17 ms | 15600 KB | Output is correct |
34 | Correct | 19 ms | 16032 KB | Output is correct |
35 | Correct | 26 ms | 16716 KB | Output is correct |
36 | Correct | 21 ms | 16716 KB | Output is correct |
37 | Correct | 23 ms | 16732 KB | Output is correct |
38 | Correct | 31 ms | 18192 KB | Output is correct |
39 | Correct | 22 ms | 18192 KB | Output is correct |
40 | Correct | 17 ms | 18192 KB | Output is correct |
41 | Correct | 17 ms | 18192 KB | Output is correct |
42 | Correct | 17 ms | 18192 KB | Output is correct |
43 | Correct | 151 ms | 47232 KB | Output is correct |
44 | Correct | 126 ms | 47232 KB | Output is correct |
45 | Correct | 118 ms | 47232 KB | Output is correct |
46 | Correct | 16 ms | 47232 KB | Output is correct |
47 | Correct | 17 ms | 47232 KB | Output is correct |
48 | Correct | 16 ms | 47232 KB | Output is correct |
49 | Correct | 16 ms | 47232 KB | Output is correct |
50 | Correct | 17 ms | 47232 KB | Output is correct |
51 | Correct | 16 ms | 47232 KB | Output is correct |
52 | Correct | 19 ms | 47232 KB | Output is correct |
53 | Correct | 17 ms | 47232 KB | Output is correct |
54 | Correct | 16 ms | 47232 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 14456 KB | Output is correct |
2 | Correct | 12 ms | 14456 KB | Output is correct |
3 | Correct | 13 ms | 14536 KB | Output is correct |
4 | Correct | 13 ms | 14536 KB | Output is correct |
5 | Correct | 13 ms | 14692 KB | Output is correct |
6 | Correct | 13 ms | 14692 KB | Output is correct |
7 | Correct | 13 ms | 14692 KB | Output is correct |
8 | Correct | 13 ms | 14756 KB | Output is correct |
9 | Correct | 13 ms | 14756 KB | Output is correct |
10 | Correct | 13 ms | 14756 KB | Output is correct |
11 | Correct | 12 ms | 14756 KB | Output is correct |
12 | Correct | 13 ms | 14756 KB | Output is correct |
13 | Correct | 13 ms | 14756 KB | Output is correct |
14 | Correct | 13 ms | 14756 KB | Output is correct |
15 | Correct | 13 ms | 14756 KB | Output is correct |
16 | Correct | 13 ms | 14772 KB | Output is correct |
17 | Correct | 13 ms | 14776 KB | Output is correct |
18 | Correct | 13 ms | 14780 KB | Output is correct |
19 | Correct | 13 ms | 14912 KB | Output is correct |
20 | Correct | 13 ms | 14912 KB | Output is correct |
21 | Correct | 13 ms | 14912 KB | Output is correct |
22 | Correct | 13 ms | 14912 KB | Output is correct |
23 | Correct | 13 ms | 14912 KB | Output is correct |
24 | Correct | 13 ms | 14912 KB | Output is correct |
25 | Correct | 13 ms | 14912 KB | Output is correct |
26 | Correct | 13 ms | 14912 KB | Output is correct |
27 | Correct | 14 ms | 14912 KB | Output is correct |
28 | Correct | 13 ms | 14912 KB | Output is correct |
29 | Correct | 16 ms | 14912 KB | Output is correct |
30 | Correct | 14 ms | 14976 KB | Output is correct |
31 | Correct | 15 ms | 15368 KB | Output is correct |
32 | Correct | 18 ms | 15432 KB | Output is correct |
33 | Correct | 17 ms | 15600 KB | Output is correct |
34 | Correct | 19 ms | 16032 KB | Output is correct |
35 | Correct | 26 ms | 16716 KB | Output is correct |
36 | Correct | 21 ms | 16716 KB | Output is correct |
37 | Correct | 23 ms | 16732 KB | Output is correct |
38 | Correct | 31 ms | 18192 KB | Output is correct |
39 | Correct | 22 ms | 18192 KB | Output is correct |
40 | Correct | 17 ms | 18192 KB | Output is correct |
41 | Correct | 17 ms | 18192 KB | Output is correct |
42 | Correct | 17 ms | 18192 KB | Output is correct |
43 | Correct | 151 ms | 47232 KB | Output is correct |
44 | Correct | 126 ms | 47232 KB | Output is correct |
45 | Correct | 118 ms | 47232 KB | Output is correct |
46 | Correct | 16 ms | 47232 KB | Output is correct |
47 | Correct | 17 ms | 47232 KB | Output is correct |
48 | Correct | 16 ms | 47232 KB | Output is correct |
49 | Correct | 16 ms | 47232 KB | Output is correct |
50 | Correct | 17 ms | 47232 KB | Output is correct |
51 | Correct | 16 ms | 47232 KB | Output is correct |
52 | Correct | 19 ms | 47232 KB | Output is correct |
53 | Correct | 17 ms | 47232 KB | Output is correct |
54 | Correct | 16 ms | 47232 KB | Output is correct |
55 | Correct | 51 ms | 47232 KB | Output is correct |
56 | Correct | 317 ms | 72248 KB | Output is correct |
57 | Correct | 646 ms | 126096 KB | Output is correct |
58 | Correct | 749 ms | 146504 KB | Output is correct |
59 | Correct | 1742 ms | 303128 KB | Output is correct |
60 | Correct | 1675 ms | 303128 KB | Output is correct |
61 | Execution timed out | 2101 ms | 373772 KB | Time limit exceeded |
62 | Halted | 0 ms | 0 KB | - |