답안 #946397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946397 2024-03-14T15:54:32 Z vjudge1 Magic Tree (CEOI19_magictree) C++17
100 / 100
152 ms 31628 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 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 4 ms 8796 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 12632 KB Output is correct
2 Correct 59 ms 19472 KB Output is correct
3 Correct 152 ms 15888 KB Output is correct
4 Correct 127 ms 15296 KB Output is correct
5 Correct 128 ms 15572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9304 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 96 ms 27768 KB Output is correct
5 Correct 110 ms 31628 KB Output is correct
6 Correct 119 ms 27764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 10832 KB Output is correct
2 Correct 89 ms 10780 KB Output is correct
3 Correct 85 ms 17632 KB Output is correct
4 Correct 75 ms 15484 KB Output is correct
5 Correct 89 ms 27728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 4 ms 8796 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 89 ms 10896 KB Output is correct
11 Correct 93 ms 10844 KB Output is correct
12 Correct 80 ms 17724 KB Output is correct
13 Correct 69 ms 15340 KB Output is correct
14 Correct 76 ms 27764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9308 KB Output is correct
2 Correct 30 ms 10920 KB Output is correct
3 Correct 37 ms 10844 KB Output is correct
4 Correct 35 ms 10840 KB Output is correct
5 Correct 22 ms 10052 KB Output is correct
6 Correct 33 ms 13648 KB Output is correct
7 Correct 39 ms 17684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 4 ms 8796 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 ms 9304 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 96 ms 27768 KB Output is correct
14 Correct 110 ms 31628 KB Output is correct
15 Correct 119 ms 27764 KB Output is correct
16 Correct 89 ms 10896 KB Output is correct
17 Correct 93 ms 10844 KB Output is correct
18 Correct 80 ms 17724 KB Output is correct
19 Correct 69 ms 15340 KB Output is correct
20 Correct 76 ms 27764 KB Output is correct
21 Correct 22 ms 9564 KB Output is correct
22 Correct 88 ms 11348 KB Output is correct
23 Correct 104 ms 13656 KB Output is correct
24 Correct 140 ms 15756 KB Output is correct
25 Correct 85 ms 15328 KB Output is correct
26 Correct 129 ms 18636 KB Output is correct
27 Correct 117 ms 20240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 4 ms 8796 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 70 ms 12632 KB Output is correct
11 Correct 59 ms 19472 KB Output is correct
12 Correct 152 ms 15888 KB Output is correct
13 Correct 127 ms 15296 KB Output is correct
14 Correct 128 ms 15572 KB Output is correct
15 Correct 3 ms 9304 KB Output is correct
16 Correct 3 ms 9052 KB Output is correct
17 Correct 2 ms 9052 KB Output is correct
18 Correct 96 ms 27768 KB Output is correct
19 Correct 110 ms 31628 KB Output is correct
20 Correct 119 ms 27764 KB Output is correct
21 Correct 91 ms 10832 KB Output is correct
22 Correct 89 ms 10780 KB Output is correct
23 Correct 85 ms 17632 KB Output is correct
24 Correct 75 ms 15484 KB Output is correct
25 Correct 89 ms 27728 KB Output is correct
26 Correct 89 ms 10896 KB Output is correct
27 Correct 93 ms 10844 KB Output is correct
28 Correct 80 ms 17724 KB Output is correct
29 Correct 69 ms 15340 KB Output is correct
30 Correct 76 ms 27764 KB Output is correct
31 Correct 9 ms 9308 KB Output is correct
32 Correct 30 ms 10920 KB Output is correct
33 Correct 37 ms 10844 KB Output is correct
34 Correct 35 ms 10840 KB Output is correct
35 Correct 22 ms 10052 KB Output is correct
36 Correct 33 ms 13648 KB Output is correct
37 Correct 39 ms 17684 KB Output is correct
38 Correct 22 ms 9564 KB Output is correct
39 Correct 88 ms 11348 KB Output is correct
40 Correct 104 ms 13656 KB Output is correct
41 Correct 140 ms 15756 KB Output is correct
42 Correct 85 ms 15328 KB Output is correct
43 Correct 129 ms 18636 KB Output is correct
44 Correct 117 ms 20240 KB Output is correct
45 Correct 24 ms 9672 KB Output is correct
46 Correct 88 ms 11180 KB Output is correct
47 Correct 94 ms 13076 KB Output is correct
48 Correct 144 ms 14984 KB Output is correct
49 Correct 98 ms 15340 KB Output is correct
50 Correct 135 ms 17888 KB Output is correct
51 Correct 136 ms 19528 KB Output is correct