Submission #658635

# Submission time Handle Problem Language Result Execution time Memory
658635 2022-11-13T22:27:49 Z lunchbox1 Magic Tree (CEOI19_magictree) C++17
100 / 100
284 ms 40328 KB
/*
 Magic Tree
 https://oj.uz/problem/view/CEOI19_magictree
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5;

int main() {
 ios::sync_with_stdio(0), cin.tie(0);
 int n, m, k; cin >> n >> m >> k;
 static int p[N];
 for (int i = 1; i < n; i++) cin >> p[i], p[i]--;
 static pair<int, int> e[N];
 while (m--) {
  int i, d, w; cin >> i >> d >> w, i--;
  e[i] = {d, w};
 }
 static map<int, long long> f[N];
 for (int i = n - 1; i > 0; i--) {
  if (e[i] != make_pair(0, 0)) {
   auto [d, w] = e[i];
   f[i][d] += w;
   auto it = f[i].upper_bound(d);
   while (w > 0 && it != f[i].end()) {
    long long u = min((long long) w, it->second);
    w -= u, it->second -= u, ++it;
   }
  }
  int j = p[i];
  if (f[i].size() > f[j].size()) swap(f[i], f[j]);
  for (auto [k, v] : f[i]) f[j][k] += v;
 }
 long long ans = 0;
 for (auto [k, v] : f[0]) ans += v;
 cout << ans << '\n';
 return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4936 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 16828 KB Output is correct
2 Correct 32 ms 9676 KB Output is correct
3 Correct 144 ms 39900 KB Output is correct
4 Correct 73 ms 17624 KB Output is correct
5 Correct 106 ms 22760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 58 ms 12000 KB Output is correct
5 Correct 54 ms 12004 KB Output is correct
6 Correct 284 ms 11956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 12224 KB Output is correct
2 Correct 43 ms 11164 KB Output is correct
3 Correct 35 ms 9536 KB Output is correct
4 Correct 37 ms 13508 KB Output is correct
5 Correct 37 ms 8196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4936 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4932 KB Output is correct
10 Correct 56 ms 16616 KB Output is correct
11 Correct 54 ms 14844 KB Output is correct
12 Correct 33 ms 8908 KB Output is correct
13 Correct 36 ms 12840 KB Output is correct
14 Correct 37 ms 7572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5588 KB Output is correct
2 Correct 11 ms 6928 KB Output is correct
3 Correct 11 ms 6936 KB Output is correct
4 Correct 11 ms 6932 KB Output is correct
5 Correct 8 ms 6480 KB Output is correct
6 Correct 13 ms 6804 KB Output is correct
7 Correct 15 ms 6800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4936 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4932 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 58 ms 12000 KB Output is correct
14 Correct 54 ms 12004 KB Output is correct
15 Correct 284 ms 11956 KB Output is correct
16 Correct 56 ms 16616 KB Output is correct
17 Correct 54 ms 14844 KB Output is correct
18 Correct 33 ms 8908 KB Output is correct
19 Correct 36 ms 12840 KB Output is correct
20 Correct 37 ms 7572 KB Output is correct
21 Correct 20 ms 9740 KB Output is correct
22 Correct 67 ms 19028 KB Output is correct
23 Correct 71 ms 24056 KB Output is correct
24 Correct 136 ms 40044 KB Output is correct
25 Correct 70 ms 16924 KB Output is correct
26 Correct 106 ms 19216 KB Output is correct
27 Correct 102 ms 15264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4936 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4932 KB Output is correct
10 Correct 48 ms 16828 KB Output is correct
11 Correct 32 ms 9676 KB Output is correct
12 Correct 144 ms 39900 KB Output is correct
13 Correct 73 ms 17624 KB Output is correct
14 Correct 106 ms 22760 KB Output is correct
15 Correct 4 ms 5068 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 58 ms 12000 KB Output is correct
19 Correct 54 ms 12004 KB Output is correct
20 Correct 284 ms 11956 KB Output is correct
21 Correct 43 ms 12224 KB Output is correct
22 Correct 43 ms 11164 KB Output is correct
23 Correct 35 ms 9536 KB Output is correct
24 Correct 37 ms 13508 KB Output is correct
25 Correct 37 ms 8196 KB Output is correct
26 Correct 56 ms 16616 KB Output is correct
27 Correct 54 ms 14844 KB Output is correct
28 Correct 33 ms 8908 KB Output is correct
29 Correct 36 ms 12840 KB Output is correct
30 Correct 37 ms 7572 KB Output is correct
31 Correct 5 ms 5588 KB Output is correct
32 Correct 11 ms 6928 KB Output is correct
33 Correct 11 ms 6936 KB Output is correct
34 Correct 11 ms 6932 KB Output is correct
35 Correct 8 ms 6480 KB Output is correct
36 Correct 13 ms 6804 KB Output is correct
37 Correct 15 ms 6800 KB Output is correct
38 Correct 20 ms 9740 KB Output is correct
39 Correct 67 ms 19028 KB Output is correct
40 Correct 71 ms 24056 KB Output is correct
41 Correct 136 ms 40044 KB Output is correct
42 Correct 70 ms 16924 KB Output is correct
43 Correct 106 ms 19216 KB Output is correct
44 Correct 102 ms 15264 KB Output is correct
45 Correct 21 ms 9972 KB Output is correct
46 Correct 60 ms 19388 KB Output is correct
47 Correct 72 ms 24336 KB Output is correct
48 Correct 156 ms 40328 KB Output is correct
49 Correct 80 ms 17612 KB Output is correct
50 Correct 104 ms 19960 KB Output is correct
51 Correct 110 ms 15892 KB Output is correct