Submission #488593

# Submission time Handle Problem Language Result Execution time Memory
488593 2021-11-19T17:58:30 Z JovanB Magic Tree (CEOI19_magictree) C++17
100 / 100
239 ms 36188 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

const int N = 100000;

map <int, ll> q[N+5];
int gde[N+5];
int t[N+5], val[N+5];

vector <int> graf[N+5];

void dfs(int v){
    int mx = 0;
    for(auto c : graf[v]){
        dfs(c);
        if(!mx || q[gde[c]].size() > q[gde[mx]].size()) mx = c;
    }
    if(!mx){
        gde[v] = v;
        if(val[v]) q[v][t[v]] += val[v];
        return;
    }
    gde[v] = gde[mx];
    for(auto c : graf[v]){
        if(c == mx) continue;
        for(auto h : q[gde[c]]) q[gde[v]][h.first] += h.second;
    }
    if(val[v]){
        q[gde[v]][t[v]] += val[v];
        auto x = q[gde[v]].upper_bound(t[v]);
        x->second -= val[v];
        while(x != q[gde[v]].end()){
            auto y = x;
            y++;
            if(x->second >= 0) break;
            if(y != q[gde[v]].end()) y->second += x->second;
            q[gde[v]].erase(x->first);
            x = y;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, m, k;
    cin >> n >> m >> k;
    for(int i=2; i<=n; i++){
        int x;
        cin >> x;
        graf[x].push_back(i);
    }
    for(int i=1; i<=m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        t[a] = b, val[a] = c;
    }
    dfs(1);
    ll res = 0;
    for(auto c : q[gde[1]]) res += c.second;
    cout << res << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7376 KB Output is correct
2 Correct 5 ms 7376 KB Output is correct
3 Correct 5 ms 7280 KB Output is correct
4 Correct 5 ms 7376 KB Output is correct
5 Correct 5 ms 7368 KB Output is correct
6 Correct 5 ms 7376 KB Output is correct
7 Correct 5 ms 7376 KB Output is correct
8 Correct 5 ms 7364 KB Output is correct
9 Correct 8 ms 7272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 18644 KB Output is correct
2 Correct 89 ms 20024 KB Output is correct
3 Correct 167 ms 35944 KB Output is correct
4 Correct 124 ms 20300 KB Output is correct
5 Correct 198 ms 22292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7504 KB Output is correct
2 Correct 5 ms 7508 KB Output is correct
3 Correct 5 ms 7504 KB Output is correct
4 Correct 60 ms 27552 KB Output is correct
5 Correct 90 ms 31624 KB Output is correct
6 Correct 75 ms 27704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 15916 KB Output is correct
2 Correct 102 ms 15148 KB Output is correct
3 Correct 90 ms 19832 KB Output is correct
4 Correct 40 ms 16316 KB Output is correct
5 Correct 61 ms 27768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7376 KB Output is correct
2 Correct 5 ms 7376 KB Output is correct
3 Correct 5 ms 7280 KB Output is correct
4 Correct 5 ms 7376 KB Output is correct
5 Correct 5 ms 7368 KB Output is correct
6 Correct 5 ms 7376 KB Output is correct
7 Correct 5 ms 7376 KB Output is correct
8 Correct 5 ms 7364 KB Output is correct
9 Correct 8 ms 7272 KB Output is correct
10 Correct 193 ms 19164 KB Output is correct
11 Correct 124 ms 17964 KB Output is correct
12 Correct 64 ms 19164 KB Output is correct
13 Correct 42 ms 15552 KB Output is correct
14 Correct 80 ms 27260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8208 KB Output is correct
2 Correct 46 ms 10756 KB Output is correct
3 Correct 64 ms 10776 KB Output is correct
4 Correct 51 ms 10880 KB Output is correct
5 Correct 13 ms 9168 KB Output is correct
6 Correct 42 ms 13272 KB Output is correct
7 Correct 44 ms 17276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7376 KB Output is correct
2 Correct 5 ms 7376 KB Output is correct
3 Correct 5 ms 7280 KB Output is correct
4 Correct 5 ms 7376 KB Output is correct
5 Correct 5 ms 7368 KB Output is correct
6 Correct 5 ms 7376 KB Output is correct
7 Correct 5 ms 7376 KB Output is correct
8 Correct 5 ms 7364 KB Output is correct
9 Correct 8 ms 7272 KB Output is correct
10 Correct 6 ms 7504 KB Output is correct
11 Correct 5 ms 7508 KB Output is correct
12 Correct 5 ms 7504 KB Output is correct
13 Correct 60 ms 27552 KB Output is correct
14 Correct 90 ms 31624 KB Output is correct
15 Correct 75 ms 27704 KB Output is correct
16 Correct 193 ms 19164 KB Output is correct
17 Correct 124 ms 17964 KB Output is correct
18 Correct 64 ms 19164 KB Output is correct
19 Correct 42 ms 15552 KB Output is correct
20 Correct 80 ms 27260 KB Output is correct
21 Correct 31 ms 11380 KB Output is correct
22 Correct 110 ms 20428 KB Output is correct
23 Correct 116 ms 24792 KB Output is correct
24 Correct 196 ms 36188 KB Output is correct
25 Correct 126 ms 19596 KB Output is correct
26 Correct 120 ms 22600 KB Output is correct
27 Correct 95 ms 21916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7376 KB Output is correct
2 Correct 5 ms 7376 KB Output is correct
3 Correct 5 ms 7280 KB Output is correct
4 Correct 5 ms 7376 KB Output is correct
5 Correct 5 ms 7368 KB Output is correct
6 Correct 5 ms 7376 KB Output is correct
7 Correct 5 ms 7376 KB Output is correct
8 Correct 5 ms 7364 KB Output is correct
9 Correct 8 ms 7272 KB Output is correct
10 Correct 113 ms 18644 KB Output is correct
11 Correct 89 ms 20024 KB Output is correct
12 Correct 167 ms 35944 KB Output is correct
13 Correct 124 ms 20300 KB Output is correct
14 Correct 198 ms 22292 KB Output is correct
15 Correct 6 ms 7504 KB Output is correct
16 Correct 5 ms 7508 KB Output is correct
17 Correct 5 ms 7504 KB Output is correct
18 Correct 60 ms 27552 KB Output is correct
19 Correct 90 ms 31624 KB Output is correct
20 Correct 75 ms 27704 KB Output is correct
21 Correct 101 ms 15916 KB Output is correct
22 Correct 102 ms 15148 KB Output is correct
23 Correct 90 ms 19832 KB Output is correct
24 Correct 40 ms 16316 KB Output is correct
25 Correct 61 ms 27768 KB Output is correct
26 Correct 193 ms 19164 KB Output is correct
27 Correct 124 ms 17964 KB Output is correct
28 Correct 64 ms 19164 KB Output is correct
29 Correct 42 ms 15552 KB Output is correct
30 Correct 80 ms 27260 KB Output is correct
31 Correct 10 ms 8208 KB Output is correct
32 Correct 46 ms 10756 KB Output is correct
33 Correct 64 ms 10776 KB Output is correct
34 Correct 51 ms 10880 KB Output is correct
35 Correct 13 ms 9168 KB Output is correct
36 Correct 42 ms 13272 KB Output is correct
37 Correct 44 ms 17276 KB Output is correct
38 Correct 31 ms 11380 KB Output is correct
39 Correct 110 ms 20428 KB Output is correct
40 Correct 116 ms 24792 KB Output is correct
41 Correct 196 ms 36188 KB Output is correct
42 Correct 126 ms 19596 KB Output is correct
43 Correct 120 ms 22600 KB Output is correct
44 Correct 95 ms 21916 KB Output is correct
45 Correct 40 ms 11228 KB Output is correct
46 Correct 122 ms 20004 KB Output is correct
47 Correct 103 ms 23352 KB Output is correct
48 Correct 239 ms 33420 KB Output is correct
49 Correct 108 ms 20296 KB Output is correct
50 Correct 139 ms 22748 KB Output is correct
51 Correct 111 ms 21996 KB Output is correct