Submission #646272

# Submission time Handle Problem Language Result Execution time Memory
646272 2022-09-29T11:18:32 Z Pety Magic Tree (CEOI19_magictree) C++14
100 / 100
136 ms 36028 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

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



void dfs (ll 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]; 
    ll x = 0;
    while (1) {
      auto it = aib[nod].upper_bound(d[nod]);
      if (it == aib[nod].end())
        break;
      if (it->second <= w[nod] - x) {
        x += it->second;
        aib[nod].erase(it);
      
      }
      else {
        it->second -= w[nod];
        it->second += x;
        break;
      }
    }
  }
}


int main () 
{
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (ll i = 2; i <= n; i++) {
    ll x;
    cin >> x;
    G[x].push_back(i);
  }
  for (ll i = 1; i <= m; i++) {
    ll 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;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7384 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 18504 KB Output is correct
2 Correct 45 ms 19020 KB Output is correct
3 Correct 133 ms 36028 KB Output is correct
4 Correct 76 ms 19236 KB Output is correct
5 Correct 136 ms 20824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7516 KB Output is correct
2 Correct 5 ms 7520 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
4 Correct 49 ms 26184 KB Output is correct
5 Correct 70 ms 30228 KB Output is correct
6 Correct 64 ms 26196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 14516 KB Output is correct
2 Correct 71 ms 13820 KB Output is correct
3 Correct 53 ms 18272 KB Output is correct
4 Correct 40 ms 15348 KB Output is correct
5 Correct 48 ms 26160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7384 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 83 ms 17396 KB Output is correct
11 Correct 67 ms 16352 KB Output is correct
12 Correct 50 ms 18288 KB Output is correct
13 Correct 35 ms 15364 KB Output is correct
14 Correct 43 ms 26188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8348 KB Output is correct
2 Correct 29 ms 11488 KB Output is correct
3 Correct 28 ms 11468 KB Output is correct
4 Correct 29 ms 11556 KB Output is correct
5 Correct 11 ms 10076 KB Output is correct
6 Correct 25 ms 14036 KB Output is correct
7 Correct 27 ms 17708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7384 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 5 ms 7516 KB Output is correct
11 Correct 5 ms 7520 KB Output is correct
12 Correct 5 ms 7508 KB Output is correct
13 Correct 49 ms 26184 KB Output is correct
14 Correct 70 ms 30228 KB Output is correct
15 Correct 64 ms 26196 KB Output is correct
16 Correct 83 ms 17396 KB Output is correct
17 Correct 67 ms 16352 KB Output is correct
18 Correct 50 ms 18288 KB Output is correct
19 Correct 35 ms 15364 KB Output is correct
20 Correct 43 ms 26188 KB Output is correct
21 Correct 20 ms 10728 KB Output is correct
22 Correct 65 ms 18720 KB Output is correct
23 Correct 87 ms 21980 KB Output is correct
24 Correct 132 ms 29736 KB Output is correct
25 Correct 74 ms 19072 KB Output is correct
26 Correct 88 ms 20900 KB Output is correct
27 Correct 73 ms 19808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7384 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 64 ms 18504 KB Output is correct
11 Correct 45 ms 19020 KB Output is correct
12 Correct 133 ms 36028 KB Output is correct
13 Correct 76 ms 19236 KB Output is correct
14 Correct 136 ms 20824 KB Output is correct
15 Correct 5 ms 7516 KB Output is correct
16 Correct 5 ms 7520 KB Output is correct
17 Correct 5 ms 7508 KB Output is correct
18 Correct 49 ms 26184 KB Output is correct
19 Correct 70 ms 30228 KB Output is correct
20 Correct 64 ms 26196 KB Output is correct
21 Correct 69 ms 14516 KB Output is correct
22 Correct 71 ms 13820 KB Output is correct
23 Correct 53 ms 18272 KB Output is correct
24 Correct 40 ms 15348 KB Output is correct
25 Correct 48 ms 26160 KB Output is correct
26 Correct 83 ms 17396 KB Output is correct
27 Correct 67 ms 16352 KB Output is correct
28 Correct 50 ms 18288 KB Output is correct
29 Correct 35 ms 15364 KB Output is correct
30 Correct 43 ms 26188 KB Output is correct
31 Correct 8 ms 8348 KB Output is correct
32 Correct 29 ms 11488 KB Output is correct
33 Correct 28 ms 11468 KB Output is correct
34 Correct 29 ms 11556 KB Output is correct
35 Correct 11 ms 10076 KB Output is correct
36 Correct 25 ms 14036 KB Output is correct
37 Correct 27 ms 17708 KB Output is correct
38 Correct 20 ms 10728 KB Output is correct
39 Correct 65 ms 18720 KB Output is correct
40 Correct 87 ms 21980 KB Output is correct
41 Correct 132 ms 29736 KB Output is correct
42 Correct 74 ms 19072 KB Output is correct
43 Correct 88 ms 20900 KB Output is correct
44 Correct 73 ms 19808 KB Output is correct
45 Correct 25 ms 11432 KB Output is correct
46 Correct 72 ms 20876 KB Output is correct
47 Correct 83 ms 24268 KB Output is correct
48 Correct 130 ms 34328 KB Output is correct
49 Correct 78 ms 21156 KB Output is correct
50 Correct 128 ms 23500 KB Output is correct
51 Correct 84 ms 22464 KB Output is correct