Submission #946385

#TimeUsernameProblemLanguageResultExecution timeMemory
946385AiperiiiMagic Tree (CEOI19_magictree)C++14
3 / 100
143 ms23888 KiB
#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 (stderr)

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){
      |            ~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...