답안 #966731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966731 2024-04-20T09:11:55 Z boyliguanhan Magic Tree (CEOI19_magictree) C++17
100 / 100
110 ms 32584 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 4 ms 8540 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 3 ms 10076 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 4 ms 8540 KB Output is correct
6 Correct 4 ms 8540 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 3 ms 10076 KB Output is correct
9 Correct 4 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 14856 KB Output is correct
2 Correct 35 ms 19800 KB Output is correct
3 Correct 92 ms 18516 KB Output is correct
4 Correct 65 ms 16656 KB Output is correct
5 Correct 80 ms 18560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 3 ms 10168 KB Output is correct
3 Correct 4 ms 10484 KB Output is correct
4 Correct 47 ms 32336 KB Output is correct
5 Correct 58 ms 32428 KB Output is correct
6 Correct 65 ms 32336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 14288 KB Output is correct
2 Correct 66 ms 14068 KB Output is correct
3 Correct 47 ms 21808 KB Output is correct
4 Correct 31 ms 12760 KB Output is correct
5 Correct 59 ms 32584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8540 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 3 ms 10076 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 4 ms 8540 KB Output is correct
6 Correct 4 ms 8540 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 3 ms 10076 KB Output is correct
9 Correct 4 ms 8540 KB Output is correct
10 Correct 55 ms 13392 KB Output is correct
11 Correct 51 ms 13404 KB Output is correct
12 Correct 43 ms 21040 KB Output is correct
13 Correct 28 ms 11992 KB Output is correct
14 Correct 66 ms 32084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9308 KB Output is correct
2 Correct 28 ms 12772 KB Output is correct
3 Correct 22 ms 12636 KB Output is correct
4 Correct 35 ms 12700 KB Output is correct
5 Correct 13 ms 11220 KB Output is correct
6 Correct 32 ms 15964 KB Output is correct
7 Correct 32 ms 20292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8540 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 3 ms 10076 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 4 ms 8540 KB Output is correct
6 Correct 4 ms 8540 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 3 ms 10076 KB Output is correct
9 Correct 4 ms 8540 KB Output is correct
10 Correct 3 ms 10328 KB Output is correct
11 Correct 3 ms 10168 KB Output is correct
12 Correct 4 ms 10484 KB Output is correct
13 Correct 47 ms 32336 KB Output is correct
14 Correct 58 ms 32428 KB Output is correct
15 Correct 65 ms 32336 KB Output is correct
16 Correct 55 ms 13392 KB Output is correct
17 Correct 51 ms 13404 KB Output is correct
18 Correct 43 ms 21040 KB Output is correct
19 Correct 28 ms 11992 KB Output is correct
20 Correct 66 ms 32084 KB Output is correct
21 Correct 17 ms 9820 KB Output is correct
22 Correct 63 ms 13652 KB Output is correct
23 Correct 58 ms 15408 KB Output is correct
24 Correct 102 ms 17072 KB Output is correct
25 Correct 53 ms 15760 KB Output is correct
26 Correct 82 ms 19856 KB Output is correct
27 Correct 77 ms 21828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8540 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 3 ms 10076 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 4 ms 8540 KB Output is correct
6 Correct 4 ms 8540 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 3 ms 10076 KB Output is correct
9 Correct 4 ms 8540 KB Output is correct
10 Correct 49 ms 14856 KB Output is correct
11 Correct 35 ms 19800 KB Output is correct
12 Correct 92 ms 18516 KB Output is correct
13 Correct 65 ms 16656 KB Output is correct
14 Correct 80 ms 18560 KB Output is correct
15 Correct 3 ms 10328 KB Output is correct
16 Correct 3 ms 10168 KB Output is correct
17 Correct 4 ms 10484 KB Output is correct
18 Correct 47 ms 32336 KB Output is correct
19 Correct 58 ms 32428 KB Output is correct
20 Correct 65 ms 32336 KB Output is correct
21 Correct 57 ms 14288 KB Output is correct
22 Correct 66 ms 14068 KB Output is correct
23 Correct 47 ms 21808 KB Output is correct
24 Correct 31 ms 12760 KB Output is correct
25 Correct 59 ms 32584 KB Output is correct
26 Correct 55 ms 13392 KB Output is correct
27 Correct 51 ms 13404 KB Output is correct
28 Correct 43 ms 21040 KB Output is correct
29 Correct 28 ms 11992 KB Output is correct
30 Correct 66 ms 32084 KB Output is correct
31 Correct 7 ms 9308 KB Output is correct
32 Correct 28 ms 12772 KB Output is correct
33 Correct 22 ms 12636 KB Output is correct
34 Correct 35 ms 12700 KB Output is correct
35 Correct 13 ms 11220 KB Output is correct
36 Correct 32 ms 15964 KB Output is correct
37 Correct 32 ms 20292 KB Output is correct
38 Correct 17 ms 9820 KB Output is correct
39 Correct 63 ms 13652 KB Output is correct
40 Correct 58 ms 15408 KB Output is correct
41 Correct 102 ms 17072 KB Output is correct
42 Correct 53 ms 15760 KB Output is correct
43 Correct 82 ms 19856 KB Output is correct
44 Correct 77 ms 21828 KB Output is correct
45 Correct 17 ms 9860 KB Output is correct
46 Correct 67 ms 13900 KB Output is correct
47 Correct 62 ms 15704 KB Output is correct
48 Correct 110 ms 17936 KB Output is correct
49 Correct 66 ms 16864 KB Output is correct
50 Correct 84 ms 20708 KB Output is correct
51 Correct 76 ms 22616 KB Output is correct