답안 #1086539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086539 2024-09-11T02:09:31 Z juicy Magic Tree (CEOI19_magictree) C++17
100 / 100
115 ms 37308 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;

int n, m, k;
int a[N], c[N];
vector<int> g[N];
map<int, long long> mp[N];

void dfs(int u) {
  for (auto v : g[u]) {
    dfs(v);
    if (mp[u].size() < mp[v].size()) {
      mp[u].swap(mp[v]);
    }
    for (auto [x, y] : mp[v]) {
      mp[u][x] += y;
    }
  }
  mp[u][a[u]] += c[u];
  for (auto it = mp[u].upper_bound(a[u]); it != mp[u].end(); it = mp[u].erase(it)) {
    auto &cnt = (*it).second;
    long long k = min(cnt, (long long) c[u]);
    c[u] -= k;
    cnt -= k;
    if (cnt) {
      break;
    }
  }
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m >> k;
  for (int i = 2; i <= n; ++i) {
    int p; cin >> p;
    g[p].push_back(i);
  }
  while (m--) {
    int v, d, w; cin >> v >> d >> w;
    tie(a[v], c[v]) = tie(d, w);
  }
  dfs(1);
  long long res = 0;
  for (auto x : mp[1]) {
    res += x.second;
  }
  cout << res;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7308 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 21076 KB Output is correct
2 Correct 49 ms 20052 KB Output is correct
3 Correct 115 ms 37308 KB Output is correct
4 Correct 55 ms 20684 KB Output is correct
5 Correct 77 ms 21956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7664 KB Output is correct
3 Correct 5 ms 7644 KB Output is correct
4 Correct 36 ms 27228 KB Output is correct
5 Correct 58 ms 31176 KB Output is correct
6 Correct 51 ms 27416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 16212 KB Output is correct
2 Correct 45 ms 15444 KB Output is correct
3 Correct 40 ms 19540 KB Output is correct
4 Correct 28 ms 16600 KB Output is correct
5 Correct 35 ms 27484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7308 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 47 ms 18516 KB Output is correct
11 Correct 54 ms 17568 KB Output is correct
12 Correct 33 ms 19036 KB Output is correct
13 Correct 26 ms 15832 KB Output is correct
14 Correct 34 ms 26972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8908 KB Output is correct
2 Correct 24 ms 13612 KB Output is correct
3 Correct 22 ms 13648 KB Output is correct
4 Correct 24 ms 13648 KB Output is correct
5 Correct 14 ms 15068 KB Output is correct
6 Correct 24 ms 16696 KB Output is correct
7 Correct 20 ms 18268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7308 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7664 KB Output is correct
12 Correct 5 ms 7644 KB Output is correct
13 Correct 36 ms 27228 KB Output is correct
14 Correct 58 ms 31176 KB Output is correct
15 Correct 51 ms 27416 KB Output is correct
16 Correct 47 ms 18516 KB Output is correct
17 Correct 54 ms 17568 KB Output is correct
18 Correct 33 ms 19036 KB Output is correct
19 Correct 26 ms 15832 KB Output is correct
20 Correct 34 ms 26972 KB Output is correct
21 Correct 14 ms 11000 KB Output is correct
22 Correct 52 ms 21060 KB Output is correct
23 Correct 60 ms 24404 KB Output is correct
24 Correct 87 ms 31056 KB Output is correct
25 Correct 49 ms 19924 KB Output is correct
26 Correct 67 ms 21840 KB Output is correct
27 Correct 55 ms 20820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7308 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 56 ms 21076 KB Output is correct
11 Correct 49 ms 20052 KB Output is correct
12 Correct 115 ms 37308 KB Output is correct
13 Correct 55 ms 20684 KB Output is correct
14 Correct 77 ms 21956 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 3 ms 7664 KB Output is correct
17 Correct 5 ms 7644 KB Output is correct
18 Correct 36 ms 27228 KB Output is correct
19 Correct 58 ms 31176 KB Output is correct
20 Correct 51 ms 27416 KB Output is correct
21 Correct 40 ms 16212 KB Output is correct
22 Correct 45 ms 15444 KB Output is correct
23 Correct 40 ms 19540 KB Output is correct
24 Correct 28 ms 16600 KB Output is correct
25 Correct 35 ms 27484 KB Output is correct
26 Correct 47 ms 18516 KB Output is correct
27 Correct 54 ms 17568 KB Output is correct
28 Correct 33 ms 19036 KB Output is correct
29 Correct 26 ms 15832 KB Output is correct
30 Correct 34 ms 26972 KB Output is correct
31 Correct 8 ms 8908 KB Output is correct
32 Correct 24 ms 13612 KB Output is correct
33 Correct 22 ms 13648 KB Output is correct
34 Correct 24 ms 13648 KB Output is correct
35 Correct 14 ms 15068 KB Output is correct
36 Correct 24 ms 16696 KB Output is correct
37 Correct 20 ms 18268 KB Output is correct
38 Correct 14 ms 11000 KB Output is correct
39 Correct 52 ms 21060 KB Output is correct
40 Correct 60 ms 24404 KB Output is correct
41 Correct 87 ms 31056 KB Output is correct
42 Correct 49 ms 19924 KB Output is correct
43 Correct 67 ms 21840 KB Output is correct
44 Correct 55 ms 20820 KB Output is correct
45 Correct 15 ms 11352 KB Output is correct
46 Correct 53 ms 22100 KB Output is correct
47 Correct 70 ms 25680 KB Output is correct
48 Correct 91 ms 34220 KB Output is correct
49 Correct 54 ms 20692 KB Output is correct
50 Correct 66 ms 22864 KB Output is correct
51 Correct 54 ms 21848 KB Output is correct