답안 #514966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
514966 2022-01-18T23:32:29 Z CrouchingDragon Magic Tree (CEOI19_magictree) C++17
100 / 100
121 ms 37844 KB
#include <bits/stdc++.h>
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, M, K;
  std::cin >> N >> M >> K;
  std::vector<int> p(N);
  for (int u = 1; u < N; ++u) {
    std::cin >> p[u];
    --p[u];
  }
  std::vector<int> d(N), w(N);
  for (int j = 0; j < M; ++j) {
    int v;
    std::cin >> v;
    --v;
    std::cin >> d[v] >> w[v];
  }
  std::vector<std::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;
    if (iter != s[u].end()) {
      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()) {
      std::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;
  }
  std::cout << sum << '\n';
  exit(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 18628 KB Output is correct
2 Correct 24 ms 9292 KB Output is correct
3 Correct 121 ms 37844 KB Output is correct
4 Correct 65 ms 16132 KB Output is correct
5 Correct 95 ms 20552 KB Output is correct
# 결과 실행 시간 메모리 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 33 ms 6100 KB Output is correct
5 Correct 48 ms 10052 KB Output is correct
6 Correct 41 ms 6232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 10692 KB Output is correct
2 Correct 38 ms 9684 KB Output is correct
3 Correct 33 ms 7508 KB Output is correct
4 Correct 33 ms 12356 KB Output is correct
5 Correct 41 ms 6164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 60 ms 15788 KB Output is correct
11 Correct 44 ms 14072 KB Output is correct
12 Correct 32 ms 7600 KB Output is correct
13 Correct 30 ms 12380 KB Output is correct
14 Correct 27 ms 6108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2292 KB Output is correct
2 Correct 16 ms 9468 KB Output is correct
3 Correct 23 ms 9420 KB Output is correct
4 Correct 17 ms 9612 KB Output is correct
5 Correct 17 ms 12492 KB Output is correct
6 Correct 17 ms 10000 KB Output is correct
7 Correct 21 ms 7364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 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 33 ms 6100 KB Output is correct
14 Correct 48 ms 10052 KB Output is correct
15 Correct 41 ms 6232 KB Output is correct
16 Correct 60 ms 15788 KB Output is correct
17 Correct 44 ms 14072 KB Output is correct
18 Correct 32 ms 7600 KB Output is correct
19 Correct 30 ms 12380 KB Output is correct
20 Correct 27 ms 6108 KB Output is correct
21 Correct 15 ms 5740 KB Output is correct
22 Correct 56 ms 20072 KB Output is correct
23 Correct 65 ms 24900 KB Output is correct
24 Correct 120 ms 37592 KB Output is correct
25 Correct 59 ms 16088 KB Output is correct
26 Correct 78 ms 17120 KB Output is correct
27 Correct 51 ms 9980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 44 ms 18628 KB Output is correct
11 Correct 24 ms 9292 KB Output is correct
12 Correct 121 ms 37844 KB Output is correct
13 Correct 65 ms 16132 KB Output is correct
14 Correct 95 ms 20552 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 33 ms 6100 KB Output is correct
19 Correct 48 ms 10052 KB Output is correct
20 Correct 41 ms 6232 KB Output is correct
21 Correct 41 ms 10692 KB Output is correct
22 Correct 38 ms 9684 KB Output is correct
23 Correct 33 ms 7508 KB Output is correct
24 Correct 33 ms 12356 KB Output is correct
25 Correct 41 ms 6164 KB Output is correct
26 Correct 60 ms 15788 KB Output is correct
27 Correct 44 ms 14072 KB Output is correct
28 Correct 32 ms 7600 KB Output is correct
29 Correct 30 ms 12380 KB Output is correct
30 Correct 27 ms 6108 KB Output is correct
31 Correct 4 ms 2292 KB Output is correct
32 Correct 16 ms 9468 KB Output is correct
33 Correct 23 ms 9420 KB Output is correct
34 Correct 17 ms 9612 KB Output is correct
35 Correct 17 ms 12492 KB Output is correct
36 Correct 17 ms 10000 KB Output is correct
37 Correct 21 ms 7364 KB Output is correct
38 Correct 15 ms 5740 KB Output is correct
39 Correct 56 ms 20072 KB Output is correct
40 Correct 65 ms 24900 KB Output is correct
41 Correct 120 ms 37592 KB Output is correct
42 Correct 59 ms 16088 KB Output is correct
43 Correct 78 ms 17120 KB Output is correct
44 Correct 51 ms 9980 KB Output is correct
45 Correct 15 ms 5288 KB Output is correct
46 Correct 63 ms 19092 KB Output is correct
47 Correct 63 ms 23108 KB Output is correct
48 Correct 104 ms 32876 KB Output is correct
49 Correct 64 ms 16088 KB Output is correct
50 Correct 86 ms 16276 KB Output is correct
51 Correct 53 ms 9412 KB Output is correct