답안 #722544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722544 2023-04-12T09:21:07 Z bitaro1337 Magic Tree (CEOI19_magictree) C++14
100 / 100
222 ms 37772 KB
//BITARO BITARO BITARO
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
vector<int> adj[N];
map<int64_t, int64_t> mp[N];
int64_t d[N], w[N], ans;
void dfs(int u) {
    for(int v: adj[u]) {
        dfs(v);
        if(mp[v].size() > mp[u].size()) swap(mp[u], mp[v]);
        for(auto x: mp[v]) mp[u][x.first] += x.second;
    }
    if(!d[u]) return;
    mp[u][d[u]] += w[u];
    int64_t val = w[u];
    while(val > 0) {
        auto it = mp[u].upper_bound(d[u]);
        if(it == mp[u].end()) break;
        int64_t vv = it->second;
        if(val >= vv) {
            mp[u].erase(it);
        } else {
            it->second -= val;
        }
        val -= vv;
    }
}
int main() {
    int n, m, k; cin >> n >> m >> k;
    for(int i = 2; i <= n; ++i) {
        int x; cin >> x;
        adj[x].push_back(i);
    }
    for(int i = 0; i < m; ++i) {
        int a, b, c; cin >> a >> b >> c;
        d[a] = b;
        w[a] = c;
    }
    dfs(1);
    for(auto x: mp[1]) ans += x.second;
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7352 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7360 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 5 ms 7360 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 19160 KB Output is correct
2 Correct 74 ms 19688 KB Output is correct
3 Correct 213 ms 37772 KB Output is correct
4 Correct 175 ms 20736 KB Output is correct
5 Correct 177 ms 22644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 5 ms 7448 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 118 ms 28092 KB Output is correct
5 Correct 154 ms 31892 KB Output is correct
6 Correct 123 ms 27992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 16336 KB Output is correct
2 Correct 151 ms 15552 KB Output is correct
3 Correct 129 ms 20268 KB Output is correct
4 Correct 95 ms 16584 KB Output is correct
5 Correct 110 ms 28188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7352 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7360 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 5 ms 7360 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 156 ms 18392 KB Output is correct
11 Correct 115 ms 17400 KB Output is correct
12 Correct 106 ms 19560 KB Output is correct
13 Correct 78 ms 15940 KB Output is correct
14 Correct 100 ms 27576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 8288 KB Output is correct
2 Correct 63 ms 11404 KB Output is correct
3 Correct 46 ms 11212 KB Output is correct
4 Correct 49 ms 11280 KB Output is correct
5 Correct 20 ms 9628 KB Output is correct
6 Correct 48 ms 13644 KB Output is correct
7 Correct 50 ms 17648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7352 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7360 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 5 ms 7360 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 5 ms 7508 KB Output is correct
11 Correct 5 ms 7448 KB Output is correct
12 Correct 4 ms 7508 KB Output is correct
13 Correct 118 ms 28092 KB Output is correct
14 Correct 154 ms 31892 KB Output is correct
15 Correct 123 ms 27992 KB Output is correct
16 Correct 156 ms 18392 KB Output is correct
17 Correct 115 ms 17400 KB Output is correct
18 Correct 106 ms 19560 KB Output is correct
19 Correct 78 ms 15940 KB Output is correct
20 Correct 100 ms 27576 KB Output is correct
21 Correct 32 ms 10804 KB Output is correct
22 Correct 104 ms 19528 KB Output is correct
23 Correct 121 ms 22656 KB Output is correct
24 Correct 222 ms 31128 KB Output is correct
25 Correct 135 ms 19952 KB Output is correct
26 Correct 150 ms 22196 KB Output is correct
27 Correct 141 ms 21444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7352 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7360 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 5 ms 7360 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 99 ms 19160 KB Output is correct
11 Correct 74 ms 19688 KB Output is correct
12 Correct 213 ms 37772 KB Output is correct
13 Correct 175 ms 20736 KB Output is correct
14 Correct 177 ms 22644 KB Output is correct
15 Correct 5 ms 7508 KB Output is correct
16 Correct 5 ms 7448 KB Output is correct
17 Correct 4 ms 7508 KB Output is correct
18 Correct 118 ms 28092 KB Output is correct
19 Correct 154 ms 31892 KB Output is correct
20 Correct 123 ms 27992 KB Output is correct
21 Correct 141 ms 16336 KB Output is correct
22 Correct 151 ms 15552 KB Output is correct
23 Correct 129 ms 20268 KB Output is correct
24 Correct 95 ms 16584 KB Output is correct
25 Correct 110 ms 28188 KB Output is correct
26 Correct 156 ms 18392 KB Output is correct
27 Correct 115 ms 17400 KB Output is correct
28 Correct 106 ms 19560 KB Output is correct
29 Correct 78 ms 15940 KB Output is correct
30 Correct 100 ms 27576 KB Output is correct
31 Correct 15 ms 8288 KB Output is correct
32 Correct 63 ms 11404 KB Output is correct
33 Correct 46 ms 11212 KB Output is correct
34 Correct 49 ms 11280 KB Output is correct
35 Correct 20 ms 9628 KB Output is correct
36 Correct 48 ms 13644 KB Output is correct
37 Correct 50 ms 17648 KB Output is correct
38 Correct 32 ms 10804 KB Output is correct
39 Correct 104 ms 19528 KB Output is correct
40 Correct 121 ms 22656 KB Output is correct
41 Correct 222 ms 31128 KB Output is correct
42 Correct 135 ms 19952 KB Output is correct
43 Correct 150 ms 22196 KB Output is correct
44 Correct 141 ms 21444 KB Output is correct
45 Correct 46 ms 11252 KB Output is correct
46 Correct 124 ms 20480 KB Output is correct
47 Correct 143 ms 24048 KB Output is correct
48 Correct 213 ms 34156 KB Output is correct
49 Correct 158 ms 20676 KB Output is correct
50 Correct 186 ms 23244 KB Output is correct
51 Correct 161 ms 22400 KB Output is correct