# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
981711 | 2024-05-13T13:33:37 Z | duckindog | Magic Tree (CEOI19_magictree) | C++17 | 122 ms | 40632 KB |
#include <bits/stdc++.h> using namespace std; const int N = 100'000 + 10; int n, m, k; vector<int> ad[N]; int d[N], w[N]; map<int, long long> f[N]; void merge(auto& x, auto& y) { if (x.size() < y.size()) swap(x, y); for (const auto& it : y) x[it.first] += it.second; } void dfs(int u, int p = 0) { for (const auto& v : ad[u]) { if (v == p) continue; dfs(v, u); merge(f[u], f[v]); } long long sum = w[u]; auto it = f[u].lower_bound(d[u] + 1); while (it != f[u].end()) { if (sum > it->second) { sum -= it->second; f[u].erase(it); } else { it->second -= sum; break; } it = f[u].lower_bound(d[u] + 1); } f[u][d[u]] += w[u]; } int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> k; for (int i = 2; i <= n; ++i) { int v; cin >> v; ad[i].push_back(v); ad[v].push_back(i); } for (int i = 1; i <= m; ++i) { int v; cin >> v >> d[v] >> w[v]; } dfs(1); long long answer = 0; for (const auto& x : f[1]) answer += x.second; cout << answer << "\n"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8280 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8284 KB | Output is correct |
4 | Correct | 2 ms | 8040 KB | Output is correct |
5 | Correct | 2 ms | 8284 KB | Output is correct |
6 | Correct | 2 ms | 8284 KB | Output is correct |
7 | Correct | 2 ms | 8284 KB | Output is correct |
8 | Correct | 2 ms | 8280 KB | Output is correct |
9 | Correct | 2 ms | 8284 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 56 ms | 22972 KB | Output is correct |
2 | Correct | 36 ms | 19548 KB | Output is correct |
3 | Correct | 122 ms | 40632 KB | Output is correct |
4 | Correct | 60 ms | 23748 KB | Output is correct |
5 | Correct | 82 ms | 24544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8280 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8284 KB | Output is correct |
4 | Correct | 42 ms | 24124 KB | Output is correct |
5 | Correct | 60 ms | 28284 KB | Output is correct |
6 | Correct | 58 ms | 24320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 18008 KB | Output is correct |
2 | Correct | 49 ms | 16988 KB | Output is correct |
3 | Correct | 41 ms | 19176 KB | Output is correct |
4 | Correct | 33 ms | 19668 KB | Output is correct |
5 | Correct | 40 ms | 24660 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8280 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8284 KB | Output is correct |
4 | Correct | 2 ms | 8040 KB | Output is correct |
5 | Correct | 2 ms | 8284 KB | Output is correct |
6 | Correct | 2 ms | 8284 KB | Output is correct |
7 | Correct | 2 ms | 8284 KB | Output is correct |
8 | Correct | 2 ms | 8280 KB | Output is correct |
9 | Correct | 2 ms | 8284 KB | Output is correct |
10 | Correct | 57 ms | 21328 KB | Output is correct |
11 | Correct | 51 ms | 20056 KB | Output is correct |
12 | Correct | 41 ms | 18288 KB | Output is correct |
13 | Correct | 33 ms | 19144 KB | Output is correct |
14 | Correct | 37 ms | 23632 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9820 KB | Output is correct |
2 | Correct | 29 ms | 15172 KB | Output is correct |
3 | Correct | 29 ms | 15192 KB | Output is correct |
4 | Correct | 34 ms | 15272 KB | Output is correct |
5 | Correct | 18 ms | 18308 KB | Output is correct |
6 | Correct | 29 ms | 18012 KB | Output is correct |
7 | Correct | 25 ms | 17500 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8280 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8284 KB | Output is correct |
4 | Correct | 2 ms | 8040 KB | Output is correct |
5 | Correct | 2 ms | 8284 KB | Output is correct |
6 | Correct | 2 ms | 8284 KB | Output is correct |
7 | Correct | 2 ms | 8284 KB | Output is correct |
8 | Correct | 2 ms | 8280 KB | Output is correct |
9 | Correct | 2 ms | 8284 KB | Output is correct |
10 | Correct | 2 ms | 8280 KB | Output is correct |
11 | Correct | 2 ms | 8284 KB | Output is correct |
12 | Correct | 2 ms | 8284 KB | Output is correct |
13 | Correct | 42 ms | 24124 KB | Output is correct |
14 | Correct | 60 ms | 28284 KB | Output is correct |
15 | Correct | 58 ms | 24320 KB | Output is correct |
16 | Correct | 57 ms | 21328 KB | Output is correct |
17 | Correct | 51 ms | 20056 KB | Output is correct |
18 | Correct | 41 ms | 18288 KB | Output is correct |
19 | Correct | 33 ms | 19144 KB | Output is correct |
20 | Correct | 37 ms | 23632 KB | Output is correct |
21 | Correct | 17 ms | 12632 KB | Output is correct |
22 | Correct | 65 ms | 24476 KB | Output is correct |
23 | Correct | 81 ms | 28524 KB | Output is correct |
24 | Correct | 115 ms | 38644 KB | Output is correct |
25 | Correct | 57 ms | 22984 KB | Output is correct |
26 | Correct | 78 ms | 23956 KB | Output is correct |
27 | Correct | 85 ms | 21072 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8280 KB | Output is correct |
2 | Correct | 2 ms | 8284 KB | Output is correct |
3 | Correct | 2 ms | 8284 KB | Output is correct |
4 | Correct | 2 ms | 8040 KB | Output is correct |
5 | Correct | 2 ms | 8284 KB | Output is correct |
6 | Correct | 2 ms | 8284 KB | Output is correct |
7 | Correct | 2 ms | 8284 KB | Output is correct |
8 | Correct | 2 ms | 8280 KB | Output is correct |
9 | Correct | 2 ms | 8284 KB | Output is correct |
10 | Correct | 56 ms | 22972 KB | Output is correct |
11 | Correct | 36 ms | 19548 KB | Output is correct |
12 | Correct | 122 ms | 40632 KB | Output is correct |
13 | Correct | 60 ms | 23748 KB | Output is correct |
14 | Correct | 82 ms | 24544 KB | Output is correct |
15 | Correct | 2 ms | 8280 KB | Output is correct |
16 | Correct | 2 ms | 8284 KB | Output is correct |
17 | Correct | 2 ms | 8284 KB | Output is correct |
18 | Correct | 42 ms | 24124 KB | Output is correct |
19 | Correct | 60 ms | 28284 KB | Output is correct |
20 | Correct | 58 ms | 24320 KB | Output is correct |
21 | Correct | 47 ms | 18008 KB | Output is correct |
22 | Correct | 49 ms | 16988 KB | Output is correct |
23 | Correct | 41 ms | 19176 KB | Output is correct |
24 | Correct | 33 ms | 19668 KB | Output is correct |
25 | Correct | 40 ms | 24660 KB | Output is correct |
26 | Correct | 57 ms | 21328 KB | Output is correct |
27 | Correct | 51 ms | 20056 KB | Output is correct |
28 | Correct | 41 ms | 18288 KB | Output is correct |
29 | Correct | 33 ms | 19144 KB | Output is correct |
30 | Correct | 37 ms | 23632 KB | Output is correct |
31 | Correct | 6 ms | 9820 KB | Output is correct |
32 | Correct | 29 ms | 15172 KB | Output is correct |
33 | Correct | 29 ms | 15192 KB | Output is correct |
34 | Correct | 34 ms | 15272 KB | Output is correct |
35 | Correct | 18 ms | 18308 KB | Output is correct |
36 | Correct | 29 ms | 18012 KB | Output is correct |
37 | Correct | 25 ms | 17500 KB | Output is correct |
38 | Correct | 17 ms | 12632 KB | Output is correct |
39 | Correct | 65 ms | 24476 KB | Output is correct |
40 | Correct | 81 ms | 28524 KB | Output is correct |
41 | Correct | 115 ms | 38644 KB | Output is correct |
42 | Correct | 57 ms | 22984 KB | Output is correct |
43 | Correct | 78 ms | 23956 KB | Output is correct |
44 | Correct | 85 ms | 21072 KB | Output is correct |
45 | Correct | 16 ms | 12380 KB | Output is correct |
46 | Correct | 62 ms | 23732 KB | Output is correct |
47 | Correct | 76 ms | 27292 KB | Output is correct |
48 | Correct | 120 ms | 35692 KB | Output is correct |
49 | Correct | 61 ms | 24004 KB | Output is correct |
50 | Correct | 81 ms | 24148 KB | Output is correct |
51 | Correct | 75 ms | 21332 KB | Output is correct |