답안 #946385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946385 2024-03-14T15:30:07 Z Aiperiii Magic Tree (CEOI19_magictree) C++14
3 / 100
143 ms 23888 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);
        }
    }
}
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";
}

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 4 ms 9048 KB Output is correct
2 Runtime error 8 ms 17856 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 14068 KB Output is correct
2 Correct 68 ms 20488 KB Output is correct
3 Correct 143 ms 18628 KB Output is correct
4 Correct 97 ms 17348 KB Output is correct
5 Correct 120 ms 17960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 18272 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 23888 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9048 KB Output is correct
2 Runtime error 8 ms 17856 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 18780 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9048 KB Output is correct
2 Runtime error 8 ms 17856 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9048 KB Output is correct
2 Runtime error 8 ms 17856 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -