Submission #898983

#TimeUsernameProblemLanguageResultExecution timeMemory
898983alexddMagic Tree (CEOI19_magictree)C++17
47 / 100
2055 ms292776 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int 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,int>> rez[maxn+5];///{zi,suc} int getrez(int nod, int zi) { if(rez[nod].empty()) return 0; pair<int,int> aux = {zi,INF}; auto it = lower_bound(rez[nod].begin(),rez[nod].end(),aux); if(it==rez[nod].begin()) return 0; it--; pair<int,int> 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]]++; int mxm=0; for(auto it:calc) { pair<int,int> 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() { 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...