Submission #417042

#TimeUsernameProblemLanguageResultExecution timeMemory
417042errorgornWorst Reporter 4 (JOI21_worst_reporter4)C++17
0 / 100
32 ms29432 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<ll,ll> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n; int arr[200005]; int h[200005]; int c[200005]; vector<int> al[200005]; map<int,int> s[200005]; void dfs(int i,int p){ for (auto &it:al[i]){ if (it==p) continue; dfs(it,i); if (sz(s[i])<sz(s[it])) swap(s[i],s[it]); for (auto &it2:s[it]) s[i][it2.fi]+=it2.se; } s[i][0]+=c[i]; s[i][h[i]+1]+=c[i]; s[i][h[i]]-=c[i]; auto iter=s[i].find(h[i]); while ((*iter).se<0){ int temp=min((*prev(iter)).se,-(*iter).se); (*iter).se+=temp; if ((*prev(iter)).se==temp) s[i].erase(prev(iter)); else (*prev(iter)).se-=temp; } //cout<<i<<": "<<endl; //for (auto &it:s[i]) cout<<it.fi<<" "<<it.se<<endl; //cout<<endl; } int main(){ cin.tie(0); cout.tie(0); cin.sync_with_stdio(false); cin>>n; rep(x,1,n+1) cin>>arr[x]>>h[x]>>c[x]; rep(x,2,n+1) al[arr[x]].pub(x); dfs(1,-1); cout<<s[1][0]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...