Submission #240678

# Submission time Handle Problem Language Result Execution time Memory
240678 2020-06-20T15:52:45 Z karma Magic Tree (CEOI19_magictree) C++14
100 / 100
165 ms 36984 KB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
//#define int         int64_t

using namespace std;

const int N = int(1e5) + 10;
typedef pair<int, int> pii;

int n, m, k, p;
vector<int> adj[N];
pii fr[N];
map<int, ll> f[N];

void dfs(int u) {
    for(int v: adj[u]) {
        dfs(v);
        if(f[u].size() < f[v].size()) f[u].swap(f[v]);
        for(auto& ff: f[v]) f[u][ff.fi] += ff.se;
    }
    if(fr[u].fi) {
        ll tmp = 0;
        while(1) {
            auto it = f[u].upper_bound(fr[u].fi);
            if(it == f[u].end()) break;
            if(it->se + tmp > fr[u].se) {
                it->se += (tmp - fr[u].se);
                break;
            }
            tmp += it->se;
            f[u].erase(it);
        }
        f[u][fr[u].fi] += fr[u].se;
    }
    //cout << u << '\n';
    //for(auto ff: f[u]) cout << ff.fi << ' ' << ff.se << '\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m >> k;
    for(int i = 2; i <= n; ++i) {
        cin >> p;
        adj[p].pb(i);
    }
    for(int v, d, w, i = 1; i <= m; ++i) {
        cin >> v >> d >> w;
        fr[v] = mp(d, w);
    }
    dfs(1);
    ll res = 0;
    for(auto ff: f[1]) res += ff.se;
    cout << res;
}

Compilation message

magictree.cpp: In function 'int32_t main()':
magictree.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 8 ms 7296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 17784 KB Output is correct
2 Correct 57 ms 17144 KB Output is correct
3 Correct 157 ms 36984 KB Output is correct
4 Correct 105 ms 20084 KB Output is correct
5 Correct 143 ms 21628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7552 KB Output is correct
4 Correct 69 ms 20728 KB Output is correct
5 Correct 98 ms 24568 KB Output is correct
6 Correct 88 ms 22648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 13560 KB Output is correct
2 Correct 85 ms 12664 KB Output is correct
3 Correct 69 ms 15480 KB Output is correct
4 Correct 56 ms 14244 KB Output is correct
5 Correct 64 ms 20728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 8 ms 7296 KB Output is correct
10 Correct 92 ms 16248 KB Output is correct
11 Correct 89 ms 15352 KB Output is correct
12 Correct 66 ms 15480 KB Output is correct
13 Correct 47 ms 14192 KB Output is correct
14 Correct 59 ms 20728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8064 KB Output is correct
2 Correct 39 ms 9976 KB Output is correct
3 Correct 39 ms 10112 KB Output is correct
4 Correct 40 ms 9976 KB Output is correct
5 Correct 19 ms 8700 KB Output is correct
6 Correct 35 ms 11520 KB Output is correct
7 Correct 36 ms 14456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 8 ms 7296 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 9 ms 7552 KB Output is correct
13 Correct 69 ms 20728 KB Output is correct
14 Correct 98 ms 24568 KB Output is correct
15 Correct 88 ms 22648 KB Output is correct
16 Correct 92 ms 16248 KB Output is correct
17 Correct 89 ms 15352 KB Output is correct
18 Correct 66 ms 15480 KB Output is correct
19 Correct 47 ms 14192 KB Output is correct
20 Correct 59 ms 20728 KB Output is correct
21 Correct 27 ms 10744 KB Output is correct
22 Correct 90 ms 18808 KB Output is correct
23 Correct 100 ms 22008 KB Output is correct
24 Correct 155 ms 30436 KB Output is correct
25 Correct 95 ms 19320 KB Output is correct
26 Correct 118 ms 20600 KB Output is correct
27 Correct 100 ms 18936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 8 ms 7296 KB Output is correct
10 Correct 80 ms 17784 KB Output is correct
11 Correct 57 ms 17144 KB Output is correct
12 Correct 157 ms 36984 KB Output is correct
13 Correct 105 ms 20084 KB Output is correct
14 Correct 143 ms 21628 KB Output is correct
15 Correct 9 ms 7552 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 9 ms 7552 KB Output is correct
18 Correct 69 ms 20728 KB Output is correct
19 Correct 98 ms 24568 KB Output is correct
20 Correct 88 ms 22648 KB Output is correct
21 Correct 90 ms 13560 KB Output is correct
22 Correct 85 ms 12664 KB Output is correct
23 Correct 69 ms 15480 KB Output is correct
24 Correct 56 ms 14244 KB Output is correct
25 Correct 64 ms 20728 KB Output is correct
26 Correct 92 ms 16248 KB Output is correct
27 Correct 89 ms 15352 KB Output is correct
28 Correct 66 ms 15480 KB Output is correct
29 Correct 47 ms 14192 KB Output is correct
30 Correct 59 ms 20728 KB Output is correct
31 Correct 13 ms 8064 KB Output is correct
32 Correct 39 ms 9976 KB Output is correct
33 Correct 39 ms 10112 KB Output is correct
34 Correct 40 ms 9976 KB Output is correct
35 Correct 19 ms 8700 KB Output is correct
36 Correct 35 ms 11520 KB Output is correct
37 Correct 36 ms 14456 KB Output is correct
38 Correct 27 ms 10744 KB Output is correct
39 Correct 90 ms 18808 KB Output is correct
40 Correct 100 ms 22008 KB Output is correct
41 Correct 155 ms 30436 KB Output is correct
42 Correct 95 ms 19320 KB Output is correct
43 Correct 118 ms 20600 KB Output is correct
44 Correct 100 ms 18936 KB Output is correct
45 Correct 30 ms 11264 KB Output is correct
46 Correct 96 ms 19832 KB Output is correct
47 Correct 103 ms 23288 KB Output is correct
48 Correct 165 ms 33400 KB Output is correct
49 Correct 107 ms 20088 KB Output is correct
50 Correct 127 ms 21624 KB Output is correct
51 Correct 117 ms 19832 KB Output is correct