답안 #946395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946395 2024-03-14T15:53:36 Z Aiperiii Magic Tree (CEOI19_magictree) C++14
100 / 100
158 ms 33612 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e5+5;
vector <int> g[N];
int day[N],val[N];
map <int,int> mp[N];
void dfs(int v){
    int mx=0,mx_node=v;
    for(auto to : g[v]){
        dfs(to);
        if(mp[to].size()>mx){
            mx=mp[to].size();
            mx_node=to;
        }
    }
    swap(mp[v],mp[mx_node]);
    for(auto to : g[v]){
        for(auto x : mp[to]){
            mp[v][x.ff]+=x.ss;
        }
        mp[to].clear();
    }
    if(day[v]){
        mp[v][day[v]]+=val[v];
        auto it=mp[v].upper_bound(day[v]);
        int sum=0;
        while(it!=mp[v].end()){
            sum+=it->ss;
            if(sum>=val[v]){
                mp[v][it->ff]=sum-val[v];
                break;
            }
            mp[v].erase(it);
            it=mp[v].upper_bound(day[v]);
        }
    }
}
signed main(){
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=2;i<=n;i++){
        int p;
        cin>>p;
        g[p].pb(i);
    }
    for(int i=0;i<m;i++){
        int v,d,x;
        cin>>v>>d>>x;
        day[v]=d;
        val[v]=x;
    }
    dfs(1);
    int ans=0;
    for(auto x : mp[1]){
        ans+=x.ss;
    }
    cout<<ans<<"\n";
}
/*
 6 4 10
 1
 2
 1
 4
 4
 3 4 5
 4 7 2
 5 4 1
 6 9 3
 */

Compilation message

magictree.cpp: In function 'void dfs(long long int)':
magictree.cpp:16:25: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   16 |         if(mp[to].size()>mx){
      |            ~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 9036 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9056 KB Output is correct
6 Correct 2 ms 9048 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 9036 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13488 KB Output is correct
2 Correct 57 ms 20304 KB Output is correct
3 Correct 158 ms 17440 KB Output is correct
4 Correct 112 ms 16688 KB Output is correct
5 Correct 119 ms 17036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 9068 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 96 ms 29672 KB Output is correct
5 Correct 114 ms 33612 KB Output is correct
6 Correct 116 ms 29800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 12112 KB Output is correct
2 Correct 95 ms 12888 KB Output is correct
3 Correct 97 ms 19892 KB Output is correct
4 Correct 75 ms 17096 KB Output is correct
5 Correct 93 ms 29784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 9036 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9056 KB Output is correct
6 Correct 2 ms 9048 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 9036 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 92 ms 12384 KB Output is correct
11 Correct 80 ms 12116 KB Output is correct
12 Correct 83 ms 19252 KB Output is correct
13 Correct 64 ms 16456 KB Output is correct
14 Correct 83 ms 29304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9560 KB Output is correct
2 Correct 36 ms 11640 KB Output is correct
3 Correct 42 ms 11608 KB Output is correct
4 Correct 33 ms 11344 KB Output is correct
5 Correct 15 ms 10196 KB Output is correct
6 Correct 34 ms 14428 KB Output is correct
7 Correct 36 ms 18268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 9036 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9056 KB Output is correct
6 Correct 2 ms 9048 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 9036 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 2 ms 9068 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 96 ms 29672 KB Output is correct
14 Correct 114 ms 33612 KB Output is correct
15 Correct 116 ms 29800 KB Output is correct
16 Correct 92 ms 12384 KB Output is correct
17 Correct 80 ms 12116 KB Output is correct
18 Correct 83 ms 19252 KB Output is correct
19 Correct 64 ms 16456 KB Output is correct
20 Correct 83 ms 29304 KB Output is correct
21 Correct 22 ms 10072 KB Output is correct
22 Correct 75 ms 12628 KB Output is correct
23 Correct 85 ms 14672 KB Output is correct
24 Correct 134 ms 17520 KB Output is correct
25 Correct 86 ms 16880 KB Output is correct
26 Correct 128 ms 20272 KB Output is correct
27 Correct 116 ms 21892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 9036 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9056 KB Output is correct
6 Correct 2 ms 9048 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 9036 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 67 ms 13488 KB Output is correct
11 Correct 57 ms 20304 KB Output is correct
12 Correct 158 ms 17440 KB Output is correct
13 Correct 112 ms 16688 KB Output is correct
14 Correct 119 ms 17036 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 2 ms 9068 KB Output is correct
17 Correct 2 ms 9052 KB Output is correct
18 Correct 96 ms 29672 KB Output is correct
19 Correct 114 ms 33612 KB Output is correct
20 Correct 116 ms 29800 KB Output is correct
21 Correct 97 ms 12112 KB Output is correct
22 Correct 95 ms 12888 KB Output is correct
23 Correct 97 ms 19892 KB Output is correct
24 Correct 75 ms 17096 KB Output is correct
25 Correct 93 ms 29784 KB Output is correct
26 Correct 92 ms 12384 KB Output is correct
27 Correct 80 ms 12116 KB Output is correct
28 Correct 83 ms 19252 KB Output is correct
29 Correct 64 ms 16456 KB Output is correct
30 Correct 83 ms 29304 KB Output is correct
31 Correct 8 ms 9560 KB Output is correct
32 Correct 36 ms 11640 KB Output is correct
33 Correct 42 ms 11608 KB Output is correct
34 Correct 33 ms 11344 KB Output is correct
35 Correct 15 ms 10196 KB Output is correct
36 Correct 34 ms 14428 KB Output is correct
37 Correct 36 ms 18268 KB Output is correct
38 Correct 22 ms 10072 KB Output is correct
39 Correct 75 ms 12628 KB Output is correct
40 Correct 85 ms 14672 KB Output is correct
41 Correct 134 ms 17520 KB Output is correct
42 Correct 86 ms 16880 KB Output is correct
43 Correct 128 ms 20272 KB Output is correct
44 Correct 116 ms 21892 KB Output is correct
45 Correct 24 ms 10076 KB Output is correct
46 Correct 87 ms 12884 KB Output is correct
47 Correct 88 ms 14740 KB Output is correct
48 Correct 152 ms 17492 KB Output is correct
49 Correct 100 ms 17508 KB Output is correct
50 Correct 131 ms 20436 KB Output is correct
51 Correct 127 ms 22080 KB Output is correct