# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
579406 | juggernaut | Magic Tree (CEOI19_magictree) | C++14 | 161 ms | 36600 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 fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
#define printl(args...) printf(args)
#else
#define printl(args...) 0
#endif
vector<int>g[100005];
int d[100005];
int w[100005];
int n,m,k;
map<int,ll>mp[100005];
int id[100005];
void dfs(int v){
int mx=0;
for(int to:g[v]){
dfs(to);
if(!mx||mp[id[to]].size()>mp[id[mx]].size())mx=to;
}
if(!mx){
id[v]=v;
if(w[v])mp[v][d[v]]+=w[v];
return;
}
id[v]=id[mx];
for(int to:g[v])if(to^mx)for(auto tmp:mp[id[to]])mp[id[v]][tmp.fr]+=tmp.second;
mp[id[v]][d[v]]+=w[v];
auto x=mp[id[v]].upper_bound(d[v]);
x->sc-=w[v];
while(x!=mp[id[v]].end()){
auto y=x;
y++;
if(x->sc>=0)break;
if(y!=mp[id[v]].end())y->second+=x->second;
mp[id[v]].erase(x->first);
x=y;
}
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=2;i<=n;i++){
int x;
scanf("%d",&x);
g[x].push_back(i);
}
while(m--){
int v;
scanf("%d",&v);
scanf("%d%d",&d[v],&w[v]);
}
ll ans=0;
dfs(1);
for(auto to:mp[id[1]])ans+=to.sc;
cout<<ans;
}
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... |