답안 #646269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646269 2022-09-29T11:12:19 Z Pety Magic Tree (CEOI19_magictree) C++14
70 / 100
149 ms 36880 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int INF = 1e9;
const int MOD = 1e9 + 9;

int n, m, w[100002], d[100002], k;
vector<int>G[100002];
map<int, ll>aib[100002];



void dfs (int nod) {
  for (auto it : G[nod]) {
    dfs(it);
    if (aib[nod].size() < aib[it].size())
      swap(aib[nod], aib[it]);
    for (auto it2 : aib[it])
      aib[nod][it2.first] += it2.second;
  }
  if (w[nod]) {
    aib[nod][d[nod]] += w[nod]; 
    while (1) {
      auto it = aib[nod].upper_bound(d[nod]);
      if (it == aib[nod].end())
        break;
      if (it->second < w[nod])
        aib[nod].erase(it);
      else {
        it->second -= w[nod];
        break;
      }
    }
  }
}


int main () 
{
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    G[x].push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    int v;
    cin >> v;
    cin >> d[v] >> w[v];
  }
  dfs(1);
  ll ans = 0;
  for (auto it : aib[1])
    ans += it.second;
  cout << ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 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 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 17256 KB Output is correct
2 Correct 40 ms 19524 KB Output is correct
3 Correct 120 ms 36880 KB Output is correct
4 Correct 77 ms 19916 KB Output is correct
5 Correct 112 ms 21980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 5 ms 7508 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
4 Correct 49 ms 25396 KB Output is correct
5 Correct 70 ms 29200 KB Output is correct
6 Correct 70 ms 25384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 13388 KB Output is correct
2 Correct 62 ms 14700 KB Output is correct
3 Correct 65 ms 19492 KB Output is correct
4 Correct 43 ms 15820 KB Output is correct
5 Correct 45 ms 27376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 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 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 71 ms 17488 KB Output is correct
11 Correct 67 ms 16144 KB Output is correct
12 Correct 53 ms 17300 KB Output is correct
13 Correct 35 ms 14152 KB Output is correct
14 Correct 44 ms 25344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 8020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 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 7252 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 7508 KB Output is correct
12 Correct 5 ms 7508 KB Output is correct
13 Correct 49 ms 25396 KB Output is correct
14 Correct 70 ms 29200 KB Output is correct
15 Correct 70 ms 25384 KB Output is correct
16 Correct 71 ms 17488 KB Output is correct
17 Correct 67 ms 16144 KB Output is correct
18 Correct 53 ms 17300 KB Output is correct
19 Correct 35 ms 14152 KB Output is correct
20 Correct 44 ms 25344 KB Output is correct
21 Correct 20 ms 11044 KB Output is correct
22 Correct 69 ms 19248 KB Output is correct
23 Correct 78 ms 23308 KB Output is correct
24 Correct 149 ms 34476 KB Output is correct
25 Correct 67 ms 17760 KB Output is correct
26 Correct 89 ms 20520 KB Output is correct
27 Correct 81 ms 19792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 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 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 71 ms 17256 KB Output is correct
11 Correct 40 ms 19524 KB Output is correct
12 Correct 120 ms 36880 KB Output is correct
13 Correct 77 ms 19916 KB Output is correct
14 Correct 112 ms 21980 KB Output is correct
15 Correct 4 ms 7508 KB Output is correct
16 Correct 5 ms 7508 KB Output is correct
17 Correct 5 ms 7508 KB Output is correct
18 Correct 49 ms 25396 KB Output is correct
19 Correct 70 ms 29200 KB Output is correct
20 Correct 70 ms 25384 KB Output is correct
21 Correct 60 ms 13388 KB Output is correct
22 Correct 62 ms 14700 KB Output is correct
23 Correct 65 ms 19492 KB Output is correct
24 Correct 43 ms 15820 KB Output is correct
25 Correct 45 ms 27376 KB Output is correct
26 Correct 71 ms 17488 KB Output is correct
27 Correct 67 ms 16144 KB Output is correct
28 Correct 53 ms 17300 KB Output is correct
29 Correct 35 ms 14152 KB Output is correct
30 Correct 44 ms 25344 KB Output is correct
31 Incorrect 8 ms 8020 KB Output isn't correct
32 Halted 0 ms 0 KB -