Submission #1086470

# Submission time Handle Problem Language Result Execution time Memory
1086470 2024-09-10T17:45:58 Z vjudge1 Magic Tree (CEOI19_magictree) C++14
100 / 100
106 ms 39896 KB
#include<bits/stdc++.h>
using namespace std;

#define NAME ""
#define ll long long
#define pii pair < int , int >
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i ++)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i --)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i ++)
#define bit(x, i) (((x) >> (i)) & 1ll)
#define mask(x) (1ll << (x))
#define mem(f, x) memset(f, x, sizeof(f))
#define sz(x) (int32_t) (x.size())

const int nmax = 1e5;
int p[nmax + 5], t[nmax + 5], w[nmax + 5];
map < int, ll > s[nmax + 5];

signed main() {
  if (fopen(NAME".inp", "r")) {
    freopen(NAME".inp", "r", stdin);
    freopen(NAME".out", "w", stdout);
  }
  cin.tie(0)->sync_with_stdio(0);

  int n, m, k;
  cin >> n >> m >> k;

  FOR(i, 2, n) {
    cin >> p[i];
  }

  for (; m --;) {
    int v;
    cin >> v;
    cin >> t[v] >> w[v];
  }

  FORD(i, n, 2) {
    if (w[i]) {
      map < int, ll > :: iterator it = s[i].insert({t[i], 0}).fi;
      (*it).se += w[i];
      it = next(it);
      int remain = w[i];

      while (remain && it != s[i].end()) {

        if ((*it).se >= remain) {
          (*it).se -= remain;
          break;
        }

        remain -= (*it).se;
        s[i].erase(it ++);
      }
    }

    if (sz(s[i]) > sz(s[p[i]])) {
      swap(s[i], s[p[i]]);
    }

    for (auto x: s[i]) {
      s[p[i]][x.fi] += x.se;
    }
  }

  ll ans = 0;
  for (auto x: s[1]) {
    ans += x.se;
  }

  cout << ans;

  return 0;
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen(NAME".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen(NAME".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 16792 KB Output is correct
2 Correct 22 ms 9820 KB Output is correct
3 Correct 106 ms 39896 KB Output is correct
4 Correct 56 ms 17568 KB Output is correct
5 Correct 63 ms 22864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 29 ms 8264 KB Output is correct
5 Correct 49 ms 12120 KB Output is correct
6 Correct 34 ms 8280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 12156 KB Output is correct
2 Correct 31 ms 11244 KB Output is correct
3 Correct 26 ms 9556 KB Output is correct
4 Correct 26 ms 13516 KB Output is correct
5 Correct 25 ms 8332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 54 ms 16428 KB Output is correct
11 Correct 35 ms 14684 KB Output is correct
12 Correct 24 ms 9040 KB Output is correct
13 Correct 23 ms 12892 KB Output is correct
14 Correct 20 ms 7784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5724 KB Output is correct
2 Correct 8 ms 6876 KB Output is correct
3 Correct 10 ms 7004 KB Output is correct
4 Correct 9 ms 7004 KB Output is correct
5 Correct 6 ms 6492 KB Output is correct
6 Correct 10 ms 7000 KB Output is correct
7 Correct 9 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 2 ms 5212 KB Output is correct
13 Correct 29 ms 8264 KB Output is correct
14 Correct 49 ms 12120 KB Output is correct
15 Correct 34 ms 8280 KB Output is correct
16 Correct 54 ms 16428 KB Output is correct
17 Correct 35 ms 14684 KB Output is correct
18 Correct 24 ms 9040 KB Output is correct
19 Correct 23 ms 12892 KB Output is correct
20 Correct 20 ms 7784 KB Output is correct
21 Correct 18 ms 9772 KB Output is correct
22 Correct 41 ms 18696 KB Output is correct
23 Correct 53 ms 23636 KB Output is correct
24 Correct 95 ms 38480 KB Output is correct
25 Correct 45 ms 16976 KB Output is correct
26 Correct 58 ms 18080 KB Output is correct
27 Correct 54 ms 11688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 36 ms 16792 KB Output is correct
11 Correct 22 ms 9820 KB Output is correct
12 Correct 106 ms 39896 KB Output is correct
13 Correct 56 ms 17568 KB Output is correct
14 Correct 63 ms 22864 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 2 ms 5212 KB Output is correct
18 Correct 29 ms 8264 KB Output is correct
19 Correct 49 ms 12120 KB Output is correct
20 Correct 34 ms 8280 KB Output is correct
21 Correct 32 ms 12156 KB Output is correct
22 Correct 31 ms 11244 KB Output is correct
23 Correct 26 ms 9556 KB Output is correct
24 Correct 26 ms 13516 KB Output is correct
25 Correct 25 ms 8332 KB Output is correct
26 Correct 54 ms 16428 KB Output is correct
27 Correct 35 ms 14684 KB Output is correct
28 Correct 24 ms 9040 KB Output is correct
29 Correct 23 ms 12892 KB Output is correct
30 Correct 20 ms 7784 KB Output is correct
31 Correct 3 ms 5724 KB Output is correct
32 Correct 8 ms 6876 KB Output is correct
33 Correct 10 ms 7004 KB Output is correct
34 Correct 9 ms 7004 KB Output is correct
35 Correct 6 ms 6492 KB Output is correct
36 Correct 10 ms 7000 KB Output is correct
37 Correct 9 ms 6748 KB Output is correct
38 Correct 18 ms 9772 KB Output is correct
39 Correct 41 ms 18696 KB Output is correct
40 Correct 53 ms 23636 KB Output is correct
41 Correct 95 ms 38480 KB Output is correct
42 Correct 45 ms 16976 KB Output is correct
43 Correct 58 ms 18080 KB Output is correct
44 Correct 54 ms 11688 KB Output is correct
45 Correct 14 ms 9308 KB Output is correct
46 Correct 41 ms 18040 KB Output is correct
47 Correct 49 ms 22100 KB Output is correct
48 Correct 89 ms 34384 KB Output is correct
49 Correct 52 ms 17748 KB Output is correct
50 Correct 66 ms 18256 KB Output is correct
51 Correct 44 ms 11856 KB Output is correct