Submission #898987

#TimeUsernameProblemLanguageResultExecution timeMemory
898987alexddMagic Tree (CEOI19_magictree)C++17
47 / 100
2097 ms294416 KiB
#include<bits/stdc++.h> using namespace std; const long long INF = 1e18; const int maxn = 1e5; int n,m,k; int parent[maxn+5]; int w[maxn+5]; int day[maxn+5]; vector<int> con[maxn+5]; vector<pair<int,long long>> rez[maxn+5];///{zi,suc} long long getrez(int nod, int zi) { if(rez[nod].empty()) return 0; pair<int,long long> aux = {zi,INF}; auto it = lower_bound(rez[nod].begin(),rez[nod].end(),aux); if(it==rez[nod].begin()) return 0; it--; pair<int,long long> cop = *it; return cop.second; } void dfs(int nod) { map<int,int> calc; for(auto adj:con[nod]) { dfs(adj); for(auto x:rez[adj]) calc[x.first]++; } if(day[nod]!=0) calc[day[nod]]++; long long mxm=0; for(auto it:calc) { pair<int,long long> aux = {it.first, 0}; if(aux.first == day[nod]) aux.second += w[nod]; for(auto adj:con[nod]) { aux.second += getrez(adj, aux.first); } if(aux.second > mxm) { mxm = aux.second; rez[nod].push_back(aux); } } } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m>>k; for(int i=2;i<=n;i++) { cin>>parent[i]; con[parent[i]].push_back(i); } int a; for(int i=1;i<=m;i++) { cin>>a; cin>>day[a]>>w[a]; } dfs(1); cout<<rez[1].back().second; return 0; } /** */
#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...