Submission #834336

#TimeUsernameProblemLanguageResultExecution timeMemory
834336Essa2006Magic Tree (CEOI19_magictree)C++14
6 / 100
2094 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define FF first #define SS second #define all(a) a.begin(), a.end() #define mod (ll)(1000000007) int n, m, k; vector<int>P, Order; vector<array<int, 2>>Q; vector<vector<int>>A; vector<map<int, int>>Has; void pre(){ P.clear(), Order.clear(), Q.clear(), A.clear(), Has.clear(); P.resize(n+1), Q.resize(n+1), A.resize(n+1), Has.resize(n+1); } void dfs(int u){ for(int i=0;i<A[u].size();i++){ int v=A[u][i]; if(v!=P[u]) dfs(v); } Order.push_back(u); } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m>>k; pre(); for(int i=2;i<=n;i++){ cin>>P[i]; int u=i, v=P[i]; A[u].push_back(v); A[v].push_back(u); } for(int j=0;j<m;j++){ int v, d, c; cin>>v>>d>>c; Q[v]={d, c}; } dfs(1); for(int kk=0;kk<n;kk++){ int u=Order[kk]; for(int i=0;i<A[u].size();i++){ int v=A[u][i]; if(v==P[u]) continue; map<int, int>New=Has[u]; for(auto it2:Has[v]){ int d=it2.FF, benf=it2.SS, mx_before=0; for(auto it:Has[u]){ if(it.FF>d){ New[it.FF]=max(New[it.FF], benf+it.SS); } else{ mx_before=max(mx_before, it.SS); } } if(Has[u].count(d)) New[d]=max(Has[u][d], benf+mx_before); else New[d]=benf+mx_before; } Has[u]=New; } if(Q[u][0]){ map<int, int>New=Has[u]; int d=Q[u][0], benf=Q[u][1], mx_before=0; for(auto it:Has[u]){ if(it.FF>d){ break; } else{ mx_before=max(mx_before, it.SS); } } if(Has[u].count(d)) New[d]=max(Has[u][d], benf+mx_before); else New[d]=benf+mx_before; Has[u]=New; } } int ans=0; for(auto it:Has[1]){ ans=max(ans, it.SS); } cout<<ans<<endl; }

Compilation message (stderr)

magictree.cpp: In function 'void dfs(long long int)':
magictree.cpp:21:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0;i<A[u].size();i++){
      |                 ~^~~~~~~~~~~~
magictree.cpp: In function 'int main()':
magictree.cpp:46:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int i=0;i<A[u].size();i++){
      |                     ~^~~~~~~~~~~~
#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...