Submission #287983

# Submission time Handle Problem Language Result Execution time Memory
287983 2020-09-01T07:29:22 Z PeppaPig Magic Tree (CEOI19_magictree) C++14
100 / 100
203 ms 36472 KB
#include <bits/stdc++.h>

#define long long long
#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 1e5+5;

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

int sack(int u) {
    int sz = 1; pii ret(0, -1);
    for(int v : g[u]) {
        int z = sack(v);
        sz += z, ret = max(ret, pii(z, v));
    }
    if(ret.y == -1) {
        if(day[u]) mp[u][day[u]] += cost[u];
        return sz; 
    } else {
        swap(mp[u], mp[ret.y]);
        for(int v : g[u]) if(v != ret.y) 
            for(auto it : mp[v]) mp[u][it.x] += it.y;
        if(day[u]) {
            mp[u][day[u]] += cost[u];
            auto it = mp[u].upper_bound(day[u]);
            while(it != mp[u].end() && it->y <= cost[u]) {
                cost[u] -= it->y;
                it = mp[u].erase(it);
            }
            if(it != mp[u].end()) it->y -= cost[u], cost[u] = 0;
        }
        return sz;
    }
}

int main() {
    scanf("%d %d %d", &n, &m, &k);
    for(int i = 2, p; i <= n; i++) {
        scanf("%d", &p);
        g[p].emplace_back(i);
    }
    for(int i = 1, a; i <= m; i++) {
        scanf("%d", &a);
        scanf("%lld %lld", day + a, cost + a);
    }
    sack(1);
    long ans = 0;
    for(auto it : mp[1]) ans += it.y;
    printf("%lld\n", ans);

    return 0;
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |         scanf("%d", &p);
      |         ~~~~~^~~~~~~~~~
magictree.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
magictree.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         scanf("%lld %lld", day + a, cost + a);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 19576 KB Output is correct
2 Correct 77 ms 19832 KB Output is correct
3 Correct 173 ms 36472 KB Output is correct
4 Correct 109 ms 20716 KB Output is correct
5 Correct 158 ms 22692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7552 KB Output is correct
2 Correct 6 ms 7552 KB Output is correct
3 Correct 6 ms 7552 KB Output is correct
4 Correct 83 ms 28024 KB Output is correct
5 Correct 110 ms 31992 KB Output is correct
6 Correct 107 ms 28152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 16376 KB Output is correct
2 Correct 118 ms 15716 KB Output is correct
3 Correct 93 ms 20344 KB Output is correct
4 Correct 97 ms 16824 KB Output is correct
5 Correct 81 ms 28280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 124 ms 18552 KB Output is correct
11 Correct 119 ms 17528 KB Output is correct
12 Correct 88 ms 19704 KB Output is correct
13 Correct 63 ms 16112 KB Output is correct
14 Correct 76 ms 27640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8320 KB Output is correct
2 Correct 51 ms 11364 KB Output is correct
3 Correct 50 ms 11260 KB Output is correct
4 Correct 51 ms 11384 KB Output is correct
5 Correct 19 ms 9720 KB Output is correct
6 Correct 44 ms 13816 KB Output is correct
7 Correct 43 ms 17664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 6 ms 7552 KB Output is correct
11 Correct 6 ms 7552 KB Output is correct
12 Correct 6 ms 7552 KB Output is correct
13 Correct 83 ms 28024 KB Output is correct
14 Correct 110 ms 31992 KB Output is correct
15 Correct 107 ms 28152 KB Output is correct
16 Correct 124 ms 18552 KB Output is correct
17 Correct 119 ms 17528 KB Output is correct
18 Correct 88 ms 19704 KB Output is correct
19 Correct 63 ms 16112 KB Output is correct
20 Correct 76 ms 27640 KB Output is correct
21 Correct 29 ms 10892 KB Output is correct
22 Correct 117 ms 19576 KB Output is correct
23 Correct 116 ms 22904 KB Output is correct
24 Correct 171 ms 30840 KB Output is correct
25 Correct 99 ms 20080 KB Output is correct
26 Correct 145 ms 22392 KB Output is correct
27 Correct 121 ms 21496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 91 ms 19576 KB Output is correct
11 Correct 77 ms 19832 KB Output is correct
12 Correct 173 ms 36472 KB Output is correct
13 Correct 109 ms 20716 KB Output is correct
14 Correct 158 ms 22692 KB Output is correct
15 Correct 6 ms 7552 KB Output is correct
16 Correct 6 ms 7552 KB Output is correct
17 Correct 6 ms 7552 KB Output is correct
18 Correct 83 ms 28024 KB Output is correct
19 Correct 110 ms 31992 KB Output is correct
20 Correct 107 ms 28152 KB Output is correct
21 Correct 113 ms 16376 KB Output is correct
22 Correct 118 ms 15716 KB Output is correct
23 Correct 93 ms 20344 KB Output is correct
24 Correct 97 ms 16824 KB Output is correct
25 Correct 81 ms 28280 KB Output is correct
26 Correct 124 ms 18552 KB Output is correct
27 Correct 119 ms 17528 KB Output is correct
28 Correct 88 ms 19704 KB Output is correct
29 Correct 63 ms 16112 KB Output is correct
30 Correct 76 ms 27640 KB Output is correct
31 Correct 14 ms 8320 KB Output is correct
32 Correct 51 ms 11364 KB Output is correct
33 Correct 50 ms 11260 KB Output is correct
34 Correct 51 ms 11384 KB Output is correct
35 Correct 19 ms 9720 KB Output is correct
36 Correct 44 ms 13816 KB Output is correct
37 Correct 43 ms 17664 KB Output is correct
38 Correct 29 ms 10892 KB Output is correct
39 Correct 117 ms 19576 KB Output is correct
40 Correct 116 ms 22904 KB Output is correct
41 Correct 171 ms 30840 KB Output is correct
42 Correct 99 ms 20080 KB Output is correct
43 Correct 145 ms 22392 KB Output is correct
44 Correct 121 ms 21496 KB Output is correct
45 Correct 37 ms 11384 KB Output is correct
46 Correct 113 ms 20728 KB Output is correct
47 Correct 129 ms 24056 KB Output is correct
48 Correct 203 ms 33912 KB Output is correct
49 Correct 112 ms 20720 KB Output is correct
50 Correct 152 ms 23160 KB Output is correct
51 Correct 127 ms 22520 KB Output is correct