Submission #1107670

#TimeUsernameProblemLanguageResultExecution timeMemory
1107670imarnWorst Reporter 4 (JOI21_worst_reporter4)C++14
79 / 100
250 ms99660 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define plx pair<ll,int> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() #define vi vector<int> #define vvi vector<vi> #define pp pair<ll,int> #define ub(x,i) upper_bound(all(x),i)-x.begin() using namespace std; const int mxn=2e5+5; vector<int> g[mxn]; int a[mxn],h[mxn],c[mxn]; map<int,ll>dp[mxn]; bool vis[mxn]{0}; void dfs(int u){ vis[u]=1; for(auto v:g[u]){ if(vis[v])continue; dfs(v); if(dp[v].size()>dp[u].size())swap(dp[u],dp[v]); for(auto it:dp[v])dp[u][it.f]+=it.s; }dp[u][h[u]]+=c[u]; auto it = dp[u].upper_bound(h[u]); int cur=c[u]; for(;it!=dp[u].end();){ if(cur>=it->s){cur-=it->s;auto ij=it;it++;dp[u].erase(ij);} else {it->s-=cur;break;} } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n;cin>>n;ll rs=0; for(int i=1;i<=n;i++){ cin>>a[i]>>h[i]>>c[i];h[i]=-h[i]; g[a[i]].pb(i);rs+=c[i]; }dfs(1);ll rs2=0; for(auto it:dp[1])rs2+=it.s; cout<<rs-rs2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...