# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
946385 | Aiperiii | Magic Tree (CEOI19_magictree) | C++14 | 143 ms | 23888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |