답안 #709372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709372 2023-03-13T13:49:21 Z pauloamed Magic Tree (CEOI19_magictree) C++14
100 / 100
214 ms 38256 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int MAXN = 100010;
vector<int> v[MAXN];

int D[MAXN], W[MAXN];

map<int,int> f[MAXN];

void solve(int x) {
  for(auto y : v[x]) {
    solve(y);
    if(f[y].size() > f[x].size()) swap(f[y], f[x]);
    for(auto [t, w] : f[y]) f[x][t] += w;
  }

  if(D[x] == 0) return;

  f[x][D[x]] += W[x];
  int t = D[x];
  int comp = W[x];
  for(auto it = f[x].upper_bound(t); it != f[x].end(); it = f[x].upper_bound(t)) {
    if(it->second <= comp) {
      comp -= it->second;
      f[x].erase(it);
    } else {
      it->second -= comp;
      if(it->second == 0) f[x].erase(it);
      break;
    }
  }
}

int32_t main(){
  int n, m, k; cin >> n >> m >> k;
  for(int i = 1; i < n; ++i) {
    int p; cin >> p; p--;
    v[p].push_back(i);
  }

  for(int i = 0; i < m; ++i) {
    int x; cin >> x; x--;
    cin >> D[x] >> W[x];
  }

  solve(0);

  int ans = 0;
  for(auto [a, b] : f[0]) ans += b;
  cout << ans << "\n";
}

Compilation message

magictree.cpp: In function 'void solve(long long int)':
magictree.cpp:16:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   16 |     for(auto [t, w] : f[y]) f[x][t] += w;
      |              ^
magictree.cpp: In function 'int32_t main()':
magictree.cpp:51:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |   for(auto [a, b] : f[0]) ans += b;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7356 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 19404 KB Output is correct
2 Correct 82 ms 19784 KB Output is correct
3 Correct 214 ms 38256 KB Output is correct
4 Correct 150 ms 21180 KB Output is correct
5 Correct 206 ms 23076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 5 ms 7492 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
4 Correct 111 ms 27980 KB Output is correct
5 Correct 144 ms 31960 KB Output is correct
6 Correct 124 ms 28032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 16492 KB Output is correct
2 Correct 137 ms 15868 KB Output is correct
3 Correct 159 ms 20316 KB Output is correct
4 Correct 103 ms 16976 KB Output is correct
5 Correct 131 ms 28256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7356 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 130 ms 18684 KB Output is correct
11 Correct 129 ms 17664 KB Output is correct
12 Correct 107 ms 19628 KB Output is correct
13 Correct 81 ms 16444 KB Output is correct
14 Correct 93 ms 27520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8352 KB Output is correct
2 Correct 54 ms 11424 KB Output is correct
3 Correct 54 ms 11420 KB Output is correct
4 Correct 52 ms 11528 KB Output is correct
5 Correct 22 ms 10016 KB Output is correct
6 Correct 46 ms 14060 KB Output is correct
7 Correct 47 ms 17692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7356 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 5 ms 7492 KB Output is correct
12 Correct 5 ms 7508 KB Output is correct
13 Correct 111 ms 27980 KB Output is correct
14 Correct 144 ms 31960 KB Output is correct
15 Correct 124 ms 28032 KB Output is correct
16 Correct 130 ms 18684 KB Output is correct
17 Correct 129 ms 17664 KB Output is correct
18 Correct 107 ms 19628 KB Output is correct
19 Correct 81 ms 16444 KB Output is correct
20 Correct 93 ms 27520 KB Output is correct
21 Correct 30 ms 10848 KB Output is correct
22 Correct 110 ms 19808 KB Output is correct
23 Correct 128 ms 22912 KB Output is correct
24 Correct 189 ms 31400 KB Output is correct
25 Correct 160 ms 20460 KB Output is correct
26 Correct 162 ms 22480 KB Output is correct
27 Correct 139 ms 21560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7356 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 99 ms 19404 KB Output is correct
11 Correct 82 ms 19784 KB Output is correct
12 Correct 214 ms 38256 KB Output is correct
13 Correct 150 ms 21180 KB Output is correct
14 Correct 206 ms 23076 KB Output is correct
15 Correct 4 ms 7508 KB Output is correct
16 Correct 5 ms 7492 KB Output is correct
17 Correct 5 ms 7508 KB Output is correct
18 Correct 111 ms 27980 KB Output is correct
19 Correct 144 ms 31960 KB Output is correct
20 Correct 124 ms 28032 KB Output is correct
21 Correct 139 ms 16492 KB Output is correct
22 Correct 137 ms 15868 KB Output is correct
23 Correct 159 ms 20316 KB Output is correct
24 Correct 103 ms 16976 KB Output is correct
25 Correct 131 ms 28256 KB Output is correct
26 Correct 130 ms 18684 KB Output is correct
27 Correct 129 ms 17664 KB Output is correct
28 Correct 107 ms 19628 KB Output is correct
29 Correct 81 ms 16444 KB Output is correct
30 Correct 93 ms 27520 KB Output is correct
31 Correct 13 ms 8352 KB Output is correct
32 Correct 54 ms 11424 KB Output is correct
33 Correct 54 ms 11420 KB Output is correct
34 Correct 52 ms 11528 KB Output is correct
35 Correct 22 ms 10016 KB Output is correct
36 Correct 46 ms 14060 KB Output is correct
37 Correct 47 ms 17692 KB Output is correct
38 Correct 30 ms 10848 KB Output is correct
39 Correct 110 ms 19808 KB Output is correct
40 Correct 128 ms 22912 KB Output is correct
41 Correct 189 ms 31400 KB Output is correct
42 Correct 160 ms 20460 KB Output is correct
43 Correct 162 ms 22480 KB Output is correct
44 Correct 139 ms 21560 KB Output is correct
45 Correct 36 ms 11264 KB Output is correct
46 Correct 123 ms 20740 KB Output is correct
47 Correct 132 ms 24272 KB Output is correct
48 Correct 211 ms 34364 KB Output is correct
49 Correct 148 ms 21056 KB Output is correct
50 Correct 185 ms 23516 KB Output is correct
51 Correct 166 ms 22448 KB Output is correct