답안 #607228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
607228 2022-07-26T13:39:48 Z 1bin Magic Tree (CEOI19_magictree) C++14
100 / 100
152 ms 38528 KB
    #include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e5 + 5;
ll n, m, k, a, b, c, p, d[NMAX], w[NMAX], ii[NMAX];
vector<int> adj[NMAX];
map<int, ll> mp[NMAX];

void merge(int a, int b){
    if(mp[ii[a]].size() < mp[ii[b]].size()) swap(ii[a], ii[b]);
    for(auto&[x, y] : mp[ii[b]]) mp[ii[a]][x] += y;
    return;
}

void dfs(int x){
    for(int & nx : adj[x]) {
        dfs(nx); merge(x, nx);
    }
    if(w[x]){
        mp[ii[x]][d[x]] += w[x];
        auto it = mp[ii[x]].upper_bound(d[x]);
        while(it != mp[ii[x]].end()){
            if(w[x] < it->second){
                it->second -= w[x];
                break;
            }
            auto nx = next(it);
            nx->second += it->second;
            it = mp[ii[x]].erase(it);
        }
    }
    
    return;
}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) ii[i] = i;
    for(int i = 2; i <= n; i++){
        cin >> p;
        adj[p].emplace_back(i);
    }
    while(m--){
        cin >> a;
        cin >> d[a] >> w[a];
    }
    dfs(1);
    ll ans = 0;
    for(auto& [x, y] : mp[ii[1]]) ans += y;
    cout << ans;
    return 0;
}

Compilation message

magictree.cpp: In function 'void merge(int, int)':
magictree.cpp:14:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |     for(auto&[x, y] : mp[ii[b]]) mp[ii[a]][x] += y;
      |              ^
magictree.cpp: In function 'int main()':
magictree.cpp:54:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for(auto& [x, y] : mp[ii[1]]) ans += y;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 6 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 19920 KB Output is correct
2 Correct 42 ms 18668 KB Output is correct
3 Correct 151 ms 38528 KB Output is correct
4 Correct 110 ms 21532 KB Output is correct
5 Correct 107 ms 23008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7512 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 45 ms 24132 KB Output is correct
5 Correct 91 ms 28044 KB Output is correct
6 Correct 88 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 16992 KB Output is correct
2 Correct 70 ms 16344 KB Output is correct
3 Correct 55 ms 19152 KB Output is correct
4 Correct 57 ms 17388 KB Output is correct
5 Correct 48 ms 24268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 6 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 71 ms 19228 KB Output is correct
11 Correct 72 ms 18224 KB Output is correct
12 Correct 66 ms 18528 KB Output is correct
13 Correct 38 ms 16844 KB Output is correct
14 Correct 59 ms 23628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 8404 KB Output is correct
2 Correct 37 ms 11996 KB Output is correct
3 Correct 43 ms 12008 KB Output is correct
4 Correct 37 ms 12088 KB Output is correct
5 Correct 17 ms 10428 KB Output is correct
6 Correct 46 ms 13544 KB Output is correct
7 Correct 41 ms 16556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 6 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 4 ms 7508 KB Output is correct
12 Correct 4 ms 7508 KB Output is correct
13 Correct 45 ms 24132 KB Output is correct
14 Correct 91 ms 28044 KB Output is correct
15 Correct 88 ms 24144 KB Output is correct
16 Correct 71 ms 19228 KB Output is correct
17 Correct 72 ms 18224 KB Output is correct
18 Correct 66 ms 18528 KB Output is correct
19 Correct 38 ms 16844 KB Output is correct
20 Correct 59 ms 23628 KB Output is correct
21 Correct 21 ms 11028 KB Output is correct
22 Correct 75 ms 20352 KB Output is correct
23 Correct 96 ms 23464 KB Output is correct
24 Correct 125 ms 31904 KB Output is correct
25 Correct 84 ms 20820 KB Output is correct
26 Correct 110 ms 22008 KB Output is correct
27 Correct 72 ms 20364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 6 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 63 ms 19920 KB Output is correct
11 Correct 42 ms 18668 KB Output is correct
12 Correct 151 ms 38528 KB Output is correct
13 Correct 110 ms 21532 KB Output is correct
14 Correct 107 ms 23008 KB Output is correct
15 Correct 4 ms 7512 KB Output is correct
16 Correct 4 ms 7508 KB Output is correct
17 Correct 4 ms 7508 KB Output is correct
18 Correct 45 ms 24132 KB Output is correct
19 Correct 91 ms 28044 KB Output is correct
20 Correct 88 ms 24144 KB Output is correct
21 Correct 70 ms 16992 KB Output is correct
22 Correct 70 ms 16344 KB Output is correct
23 Correct 55 ms 19152 KB Output is correct
24 Correct 57 ms 17388 KB Output is correct
25 Correct 48 ms 24268 KB Output is correct
26 Correct 71 ms 19228 KB Output is correct
27 Correct 72 ms 18224 KB Output is correct
28 Correct 66 ms 18528 KB Output is correct
29 Correct 38 ms 16844 KB Output is correct
30 Correct 59 ms 23628 KB Output is correct
31 Correct 12 ms 8404 KB Output is correct
32 Correct 37 ms 11996 KB Output is correct
33 Correct 43 ms 12008 KB Output is correct
34 Correct 37 ms 12088 KB Output is correct
35 Correct 17 ms 10428 KB Output is correct
36 Correct 46 ms 13544 KB Output is correct
37 Correct 41 ms 16556 KB Output is correct
38 Correct 21 ms 11028 KB Output is correct
39 Correct 75 ms 20352 KB Output is correct
40 Correct 96 ms 23464 KB Output is correct
41 Correct 125 ms 31904 KB Output is correct
42 Correct 84 ms 20820 KB Output is correct
43 Correct 110 ms 22008 KB Output is correct
44 Correct 72 ms 20364 KB Output is correct
45 Correct 25 ms 11496 KB Output is correct
46 Correct 75 ms 21380 KB Output is correct
47 Correct 88 ms 24812 KB Output is correct
48 Correct 152 ms 34864 KB Output is correct
49 Correct 85 ms 21480 KB Output is correct
50 Correct 127 ms 22996 KB Output is correct
51 Correct 93 ms 21292 KB Output is correct