답안 #966562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966562 2024-04-20T04:06:42 Z vjudge1 Magic Tree (CEOI19_magictree) C++17
100 / 100
111 ms 32632 KB
#include<bits/stdc++.h>
using namespace std;
#define N 7<<14
#define int long long
vector<int>adj[N];
map<int,int> dp[N];
int d[N],w[N];
void dfs(int n){
    dp[n][0];
    for(auto i:adj[n]){
        dfs(i);
        if(size(dp[n])<size(dp[i]))
            swap(dp[n],dp[i]);
        for(auto&[i,j]:dp[i])
            dp[n][i]+=j;
        dp[i].clear();
    }
    if(w[n]){
        dp[n][d[n]]+=w[n];
        auto it=dp[n].upper_bound(d[n]);
        while(it!=dp[n].end()){
            if(it->second<=w[n])
                next(it)->second+=it->second,it=next(it),dp[n].erase(prev(it));
            else {
                it->second-=w[n];
                break;
            }
        }
    }
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n,m,k,Q;
    cin>>n>>m>>k;
    for(int i=2;i<=n;i++)
        cin>>Q,adj[Q].push_back(i);
    while(m--){
        int a,b,c;
        cin>>a>>b>>c;
        d[a]=b,w[a]=c;
    }
    dfs(1);
    int ans=0;
    for(auto&[i,j]:dp[1])
        ans+=j;
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10076 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 2 ms 10148 KB Output is correct
5 Correct 2 ms 10072 KB Output is correct
6 Correct 2 ms 10076 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 2 ms 10076 KB Output is correct
9 Correct 3 ms 10076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 13908 KB Output is correct
2 Correct 34 ms 20052 KB Output is correct
3 Correct 95 ms 16284 KB Output is correct
4 Correct 52 ms 14580 KB Output is correct
5 Correct 63 ms 16288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10332 KB Output is correct
2 Correct 3 ms 10328 KB Output is correct
3 Correct 2 ms 10328 KB Output is correct
4 Correct 45 ms 32496 KB Output is correct
5 Correct 57 ms 32632 KB Output is correct
6 Correct 57 ms 32340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 12176 KB Output is correct
2 Correct 38 ms 12124 KB Output is correct
3 Correct 42 ms 19544 KB Output is correct
4 Correct 29 ms 11224 KB Output is correct
5 Correct 42 ms 30608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10076 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 2 ms 10148 KB Output is correct
5 Correct 2 ms 10072 KB Output is correct
6 Correct 2 ms 10076 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 2 ms 10076 KB Output is correct
9 Correct 3 ms 10076 KB Output is correct
10 Correct 47 ms 13652 KB Output is correct
11 Correct 42 ms 13400 KB Output is correct
12 Correct 40 ms 21080 KB Output is correct
13 Correct 28 ms 12248 KB Output is correct
14 Correct 40 ms 32128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 10588 KB Output is correct
2 Correct 22 ms 12776 KB Output is correct
3 Correct 22 ms 12636 KB Output is correct
4 Correct 21 ms 12636 KB Output is correct
5 Correct 11 ms 11484 KB Output is correct
6 Correct 24 ms 15964 KB Output is correct
7 Correct 25 ms 20304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10076 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 2 ms 10148 KB Output is correct
5 Correct 2 ms 10072 KB Output is correct
6 Correct 2 ms 10076 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 2 ms 10076 KB Output is correct
9 Correct 3 ms 10076 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
11 Correct 3 ms 10328 KB Output is correct
12 Correct 2 ms 10328 KB Output is correct
13 Correct 45 ms 32496 KB Output is correct
14 Correct 57 ms 32632 KB Output is correct
15 Correct 57 ms 32340 KB Output is correct
16 Correct 47 ms 13652 KB Output is correct
17 Correct 42 ms 13400 KB Output is correct
18 Correct 40 ms 21080 KB Output is correct
19 Correct 28 ms 12248 KB Output is correct
20 Correct 40 ms 32128 KB Output is correct
21 Correct 15 ms 11096 KB Output is correct
22 Correct 48 ms 13648 KB Output is correct
23 Correct 52 ms 15452 KB Output is correct
24 Correct 79 ms 17236 KB Output is correct
25 Correct 50 ms 16072 KB Output is correct
26 Correct 63 ms 19796 KB Output is correct
27 Correct 63 ms 22044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10076 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 2 ms 10148 KB Output is correct
5 Correct 2 ms 10072 KB Output is correct
6 Correct 2 ms 10076 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 2 ms 10076 KB Output is correct
9 Correct 3 ms 10076 KB Output is correct
10 Correct 44 ms 13908 KB Output is correct
11 Correct 34 ms 20052 KB Output is correct
12 Correct 95 ms 16284 KB Output is correct
13 Correct 52 ms 14580 KB Output is correct
14 Correct 63 ms 16288 KB Output is correct
15 Correct 3 ms 10332 KB Output is correct
16 Correct 3 ms 10328 KB Output is correct
17 Correct 2 ms 10328 KB Output is correct
18 Correct 45 ms 32496 KB Output is correct
19 Correct 57 ms 32632 KB Output is correct
20 Correct 57 ms 32340 KB Output is correct
21 Correct 50 ms 12176 KB Output is correct
22 Correct 38 ms 12124 KB Output is correct
23 Correct 42 ms 19544 KB Output is correct
24 Correct 29 ms 11224 KB Output is correct
25 Correct 42 ms 30608 KB Output is correct
26 Correct 47 ms 13652 KB Output is correct
27 Correct 42 ms 13400 KB Output is correct
28 Correct 40 ms 21080 KB Output is correct
29 Correct 28 ms 12248 KB Output is correct
30 Correct 40 ms 32128 KB Output is correct
31 Correct 6 ms 10588 KB Output is correct
32 Correct 22 ms 12776 KB Output is correct
33 Correct 22 ms 12636 KB Output is correct
34 Correct 21 ms 12636 KB Output is correct
35 Correct 11 ms 11484 KB Output is correct
36 Correct 24 ms 15964 KB Output is correct
37 Correct 25 ms 20304 KB Output is correct
38 Correct 15 ms 11096 KB Output is correct
39 Correct 48 ms 13648 KB Output is correct
40 Correct 52 ms 15452 KB Output is correct
41 Correct 79 ms 17236 KB Output is correct
42 Correct 50 ms 16072 KB Output is correct
43 Correct 63 ms 19796 KB Output is correct
44 Correct 63 ms 22044 KB Output is correct
45 Correct 14 ms 11356 KB Output is correct
46 Correct 52 ms 13916 KB Output is correct
47 Correct 58 ms 15696 KB Output is correct
48 Correct 111 ms 18304 KB Output is correct
49 Correct 51 ms 16844 KB Output is correct
50 Correct 75 ms 20812 KB Output is correct
51 Correct 67 ms 22612 KB Output is correct