Submission #246280

#TimeUsernameProblemLanguageResultExecution timeMemory
2462802fat2codeMagic Tree (CEOI19_magictree)C++17
3 / 100
156 ms38500 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define all(a) (a).begin(), (a).end() #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define sz() size() #define fr first #define sc second #define int long long #define mp make_pair #define rc(s) return cout<<s,0 #define rcc(s) cout<<s,exit(0) using namespace std; const int nmax = 100005; struct fruct{ int prezent, day, juice; fruct(){prezent = -1;} }a[nmax]; map<int,int>dp[nmax]; int n,m,k,dp_sub[nmax]; vector<int>nod[nmax]; void add(int indx, pair<int,int>val){ dp[indx][val.fr] += val.sc; } void rationalize(int indx, pair<int,int>val){ int precedent = dp[indx][val.fr]; dp[indx][val.fr] += val.sc; auto it = dp[indx].upper_bound(val.fr); int curr = 0; while(it != dp[indx].end()){ curr += (it->second - precedent); precedent = (it->second); if(curr > val.sc) break; else{ auto tz = it; ++it; dp[indx].erase(tz); } } if(it != dp[indx].end()){ dp[indx][it->first] = (curr - val.sc); } } void DFS(int s){ int heavy = -1, sz = 0; for(auto it : nod[s]){ DFS(it); dp_sub[s] += dp_sub[it]; if(sz < dp_sub[it]){ sz = dp_sub[it]; heavy = it; } } dp_sub[s] ++; if(heavy != -1){ swap(dp[s],dp[heavy]); } for(auto it : nod[s]){ if(it != heavy){ for(auto curr : dp[it]){ add(s,curr); } } } if(a[s].prezent == 1){ rationalize(s,{a[s].day, a[s].juice}); } } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); srand(chrono::steady_clock::now().time_since_epoch().count()); cin >> n >> m >> k; for(int i=2;i<=n;i++){ int x; cin >> x; nod[x].push_back(i); } for(int i=1;i<=m;i++){ int x,y,z; cin >> x >> y >> z; a[x].prezent = 1; a[x].day = y; a[x].juice = z; } DFS(1); int ans = 0; for(auto it : dp[1]){ ans += (it.sc); } cout << ans << '\n'; }
#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...