답안 #946388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946388 2024-03-14T15:34:42 Z Aiperiii Magic Tree (CEOI19_magictree) C++14
3 / 100
142 ms 21588 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;
            auto it2=it++;
            it--;
            if(sum>=val[v]){
                mp[v][it->ff]=sum-val[v];
                break;
            }
            mp[v].erase(it);
            it=it2;
        }
    }
}
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 2 ms 8796 KB Output is correct
2 Runtime error 10 ms 18012 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 12804 KB Output is correct
2 Correct 57 ms 19564 KB Output is correct
3 Correct 142 ms 16204 KB Output is correct
4 Correct 98 ms 15328 KB Output is correct
5 Correct 131 ms 15572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 18268 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 99 ms 21588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Runtime error 10 ms 18012 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 18520 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Runtime error 10 ms 18012 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Runtime error 10 ms 18012 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -