Submission #514968

# Submission time Handle Problem Language Result Execution time Memory
514968 2022-01-18T23:34:32 Z CrouchingDragon Magic Tree (CEOI19_magictree) C++17
100 / 100
124 ms 37756 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> p(N);
  for (int u = 1; u < N; ++u) {
    cin >> p[u];
    --p[u];
  }
  vector<int> d(N), w(N);
  for (int j = 0; j < M; ++j) {
    int v;
    cin >> v;
    --v;
    cin >> d[v] >> w[v];
  }
  vector<map<int, int64_t>> s(N);
  for (int u = N - 1; u > 0; --u) {
    auto iter = s[u].insert({d[u], 0}).first;
    iter->second += w[u];
    ++iter;
    int64_t sum = -w[u];
    while (iter != s[u].end() && iter->second + sum < 0) {
      sum += iter->second;
      iter = s[u].erase(iter);
    }
    if (iter != s[u].end()) {
      iter->second += sum;
    }
    int v = p[u];
    if (s[v].size() < s[u].size()) {
      swap(s[v], s[u]);
    }
    for (auto [d, w] : s[u]) {
      s[v][d] += w;
    }
  }
  int64_t sum = 0;
  for (auto [d, w] : s[0]) {
    sum += w;
  }
  cout << sum << '\n';
  exit(0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 236 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 18728 KB Output is correct
2 Correct 25 ms 9292 KB Output is correct
3 Correct 124 ms 37756 KB Output is correct
4 Correct 70 ms 16088 KB Output is correct
5 Correct 82 ms 20412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 35 ms 6116 KB Output is correct
5 Correct 73 ms 10076 KB Output is correct
6 Correct 48 ms 6348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 10752 KB Output is correct
2 Correct 40 ms 9664 KB Output is correct
3 Correct 33 ms 7572 KB Output is correct
4 Correct 33 ms 12336 KB Output is correct
5 Correct 30 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 236 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 52 ms 15812 KB Output is correct
11 Correct 49 ms 14188 KB Output is correct
12 Correct 54 ms 7628 KB Output is correct
13 Correct 54 ms 12356 KB Output is correct
14 Correct 28 ms 6112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2252 KB Output is correct
2 Correct 18 ms 9436 KB Output is correct
3 Correct 24 ms 9408 KB Output is correct
4 Correct 16 ms 9548 KB Output is correct
5 Correct 21 ms 12492 KB Output is correct
6 Correct 18 ms 10044 KB Output is correct
7 Correct 20 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 236 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 35 ms 6116 KB Output is correct
14 Correct 73 ms 10076 KB Output is correct
15 Correct 48 ms 6348 KB Output is correct
16 Correct 52 ms 15812 KB Output is correct
17 Correct 49 ms 14188 KB Output is correct
18 Correct 54 ms 7628 KB Output is correct
19 Correct 54 ms 12356 KB Output is correct
20 Correct 28 ms 6112 KB Output is correct
21 Correct 20 ms 5708 KB Output is correct
22 Correct 69 ms 20092 KB Output is correct
23 Correct 94 ms 24932 KB Output is correct
24 Correct 111 ms 37584 KB Output is correct
25 Correct 58 ms 16052 KB Output is correct
26 Correct 77 ms 16960 KB Output is correct
27 Correct 55 ms 10080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 236 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 49 ms 18728 KB Output is correct
11 Correct 25 ms 9292 KB Output is correct
12 Correct 124 ms 37756 KB Output is correct
13 Correct 70 ms 16088 KB Output is correct
14 Correct 82 ms 20412 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 35 ms 6116 KB Output is correct
19 Correct 73 ms 10076 KB Output is correct
20 Correct 48 ms 6348 KB Output is correct
21 Correct 49 ms 10752 KB Output is correct
22 Correct 40 ms 9664 KB Output is correct
23 Correct 33 ms 7572 KB Output is correct
24 Correct 33 ms 12336 KB Output is correct
25 Correct 30 ms 6100 KB Output is correct
26 Correct 52 ms 15812 KB Output is correct
27 Correct 49 ms 14188 KB Output is correct
28 Correct 54 ms 7628 KB Output is correct
29 Correct 54 ms 12356 KB Output is correct
30 Correct 28 ms 6112 KB Output is correct
31 Correct 5 ms 2252 KB Output is correct
32 Correct 18 ms 9436 KB Output is correct
33 Correct 24 ms 9408 KB Output is correct
34 Correct 16 ms 9548 KB Output is correct
35 Correct 21 ms 12492 KB Output is correct
36 Correct 18 ms 10044 KB Output is correct
37 Correct 20 ms 7368 KB Output is correct
38 Correct 20 ms 5708 KB Output is correct
39 Correct 69 ms 20092 KB Output is correct
40 Correct 94 ms 24932 KB Output is correct
41 Correct 111 ms 37584 KB Output is correct
42 Correct 58 ms 16052 KB Output is correct
43 Correct 77 ms 16960 KB Output is correct
44 Correct 55 ms 10080 KB Output is correct
45 Correct 23 ms 5268 KB Output is correct
46 Correct 60 ms 19088 KB Output is correct
47 Correct 64 ms 23132 KB Output is correct
48 Correct 104 ms 32816 KB Output is correct
49 Correct 66 ms 16132 KB Output is correct
50 Correct 75 ms 16336 KB Output is correct
51 Correct 56 ms 9416 KB Output is correct