Submission #953573

# Submission time Handle Problem Language Result Execution time Memory
953573 2024-03-26T08:51:44 Z LucaIlie Magic Tree (CEOI19_magictree) C++17
100 / 100
168 ms 36312 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5;
bool hasFruit[MAX_N + 1];
int fruitTime[MAX_N + 1], fruitWeight[MAX_N + 1];
vector<int> adj[MAX_N + 1];
map<int, long long> dif[MAX_N + 1];

void dfs( int u ) {
    int h = 0;
    for ( int v: adj[u] ) {
        dfs( v );
        if ( h == 0 || dif[v].size() > dif[h].size() )
            h = v;
    }

    if ( h != 0 ) {
        swap( dif[u], dif[h] );

        for ( int v: adj[u] ) {
            if ( v == h )
                continue;

            for ( auto p: dif[v] )
                dif[u][p.first] += p.second;
        }
    }

    if ( hasFruit[u] ) {
        auto p = dif[u].upper_bound( fruitTime[u] );
        long long sum = 0;
        vector<int> del;
        while ( p != dif[u].end() && fruitWeight[u] > sum + p->second ) {
            sum += p->second;
            del.push_back( p->first );
            p++;
        }
        for ( int t: del )
            dif[u].erase( t );
        dif[u][fruitTime[u]] += fruitWeight[u];
        if ( p != dif[u].end() )
            dif[u][p->first] -= fruitWeight[u] - sum;
    }
}

int main() {
    int n, m, k;

    cin >> n >> m >> k;
    for ( int v = 2; v <= n; v++ ) {
        int p;
        cin >> p;
        adj[p].push_back( v );
    }

    for ( int i = 0; i < m; i++ ) {
        int v;
        cin >> v;
        hasFruit[v] = true;
        cin >> fruitTime[v] >> fruitWeight[v];
    }

    dfs( 1 );

    long long sum = 0;
    for ( auto p: dif[1] )
        sum += p.second;

    cout << sum;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 17236 KB Output is correct
2 Correct 57 ms 19792 KB Output is correct
3 Correct 168 ms 33360 KB Output is correct
4 Correct 101 ms 18080 KB Output is correct
5 Correct 130 ms 20052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7516 KB Output is correct
2 Correct 2 ms 7472 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 96 ms 30496 KB Output is correct
5 Correct 110 ms 34388 KB Output is correct
6 Correct 120 ms 30636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 13540 KB Output is correct
2 Correct 113 ms 12780 KB Output is correct
3 Correct 95 ms 18772 KB Output is correct
4 Correct 74 ms 14244 KB Output is correct
5 Correct 108 ms 28476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 95 ms 17488 KB Output is correct
11 Correct 84 ms 16096 KB Output is correct
12 Correct 82 ms 18776 KB Output is correct
13 Correct 62 ms 14284 KB Output is correct
14 Correct 80 ms 28584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8028 KB Output is correct
2 Correct 37 ms 9884 KB Output is correct
3 Correct 31 ms 10012 KB Output is correct
4 Correct 31 ms 10016 KB Output is correct
5 Correct 18 ms 8656 KB Output is correct
6 Correct 33 ms 13052 KB Output is correct
7 Correct 43 ms 17688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 2 ms 7472 KB Output is correct
12 Correct 2 ms 7516 KB Output is correct
13 Correct 96 ms 30496 KB Output is correct
14 Correct 110 ms 34388 KB Output is correct
15 Correct 120 ms 30636 KB Output is correct
16 Correct 95 ms 17488 KB Output is correct
17 Correct 84 ms 16096 KB Output is correct
18 Correct 82 ms 18776 KB Output is correct
19 Correct 62 ms 14284 KB Output is correct
20 Correct 80 ms 28584 KB Output is correct
21 Correct 24 ms 11356 KB Output is correct
22 Correct 83 ms 20184 KB Output is correct
23 Correct 99 ms 24552 KB Output is correct
24 Correct 162 ms 36312 KB Output is correct
25 Correct 94 ms 19480 KB Output is correct
26 Correct 124 ms 23124 KB Output is correct
27 Correct 120 ms 23052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 72 ms 17236 KB Output is correct
11 Correct 57 ms 19792 KB Output is correct
12 Correct 168 ms 33360 KB Output is correct
13 Correct 101 ms 18080 KB Output is correct
14 Correct 130 ms 20052 KB Output is correct
15 Correct 2 ms 7516 KB Output is correct
16 Correct 2 ms 7472 KB Output is correct
17 Correct 2 ms 7516 KB Output is correct
18 Correct 96 ms 30496 KB Output is correct
19 Correct 110 ms 34388 KB Output is correct
20 Correct 120 ms 30636 KB Output is correct
21 Correct 106 ms 13540 KB Output is correct
22 Correct 113 ms 12780 KB Output is correct
23 Correct 95 ms 18772 KB Output is correct
24 Correct 74 ms 14244 KB Output is correct
25 Correct 108 ms 28476 KB Output is correct
26 Correct 95 ms 17488 KB Output is correct
27 Correct 84 ms 16096 KB Output is correct
28 Correct 82 ms 18776 KB Output is correct
29 Correct 62 ms 14284 KB Output is correct
30 Correct 80 ms 28584 KB Output is correct
31 Correct 8 ms 8028 KB Output is correct
32 Correct 37 ms 9884 KB Output is correct
33 Correct 31 ms 10012 KB Output is correct
34 Correct 31 ms 10016 KB Output is correct
35 Correct 18 ms 8656 KB Output is correct
36 Correct 33 ms 13052 KB Output is correct
37 Correct 43 ms 17688 KB Output is correct
38 Correct 24 ms 11356 KB Output is correct
39 Correct 83 ms 20184 KB Output is correct
40 Correct 99 ms 24552 KB Output is correct
41 Correct 162 ms 36312 KB Output is correct
42 Correct 94 ms 19480 KB Output is correct
43 Correct 124 ms 23124 KB Output is correct
44 Correct 120 ms 23052 KB Output is correct
45 Correct 27 ms 11088 KB Output is correct
46 Correct 93 ms 19664 KB Output is correct
47 Correct 97 ms 23004 KB Output is correct
48 Correct 157 ms 33108 KB Output is correct
49 Correct 111 ms 20376 KB Output is correct
50 Correct 142 ms 23136 KB Output is correct
51 Correct 130 ms 23104 KB Output is correct