Submission #965733

#TimeUsernameProblemLanguageResultExecution timeMemory
965733vjudge1Magic Tree (CEOI19_magictree)C++17
47 / 100
2067 ms45200 KiB
#include<bits/stdc++.h> using namespace std; #define N 7<<14 #define int long long vector<int>adj[N]; map<int,int> dp[N]; int d[N],w[N]; void dfs(int n){ map<int,int> add; dp[n][0]; for(auto i:adj[n]){ dfs(i); if(size(dp[n])+size(add)<size(dp[i])) { add[0]; auto it=++add.begin(); while(it!=add.end()){ it->second+=prev(it)->second; it++; } for(auto[i,j]:add) dp[n][i]=(--(dp[n].upper_bound(i)))->second; for(auto&[i,j]:dp[n]) j+=(--(add.upper_bound(i)))->second; add.clear(); swap(dp[n],dp[i]); } auto it=++dp[i].begin(); while(it!=dp[i].end()) add[it->first]+=it->second-prev(it)->second,it++; dp[i].clear(); } add[0]; auto it=++add.begin(); while(it!=add.end()){ it->second+=prev(it)->second; it++; } for(auto[i,j]:add) dp[n][i]=(--(dp[n].upper_bound(i)))->second; for(auto&[i,j]:dp[n]) j+=(--(add.upper_bound(i)))->second; it=--(dp[n].upper_bound(d[n])); int val=it->second+w[n]; dp[n][d[n]]=val; it=dp[n].find(d[n]); while(it!=dp[n].end()){ it->second=max(it->second,val); it++; } } signed main(){ cin.tie(0)->sync_with_stdio(0); int n,m,k,Q; cin>>n>>m>>k; for(int i=2;i<=n;i++) cin>>Q,adj[Q].push_back(i); while(m--){ int a,b,c; cin>>a>>b>>c; d[a]=b,w[a]=c; } dfs(1); cout<<(--dp[1].end())->second; }
#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...