Submission #483911

#TimeUsernameProblemLanguageResultExecution timeMemory
483911FatihSolakBiochips (IZhO12_biochips)C++17
100 / 100
169 ms11616 KiB
#include <bits/stdc++.h> #define N 200005 using namespace std; int n,m; vector<int> adj[N]; int par[N]; int arr[N]; int ans = 0; vector<int> dfs(int v,int c,vector<int> dp){ dp[0] = 0; vector<int> tmp = dp; for(auto u:adj[v]){ if(u == c)continue; dp = dfs(u,-1,dp); } if(c == -1){ for(int i=1;i<=m;i++){ dp[i] = max(dp[i],tmp[i-1]+arr[v]); } } else{ dp[1] = max(dp[1],arr[v]); } ans = max(ans,dp[m]); if(c != -1 && par[v]){ dfs(par[v],v,dp); } return dp; } void solve(){ cin >> n >> m; int root = 0; for(int i=1;i<=n;i++){ cin >> par[i] >> arr[i]; if(par[i] == 0)root = i; else adj[par[i]].push_back(i); } for(int i=1;i<=n;i++){ if(adj[i].empty()){ dfs(i,0,vector<int>(m+1,-1e9)); break; } } cout << ans << endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t=1; //cin>>t; while(t--){ solve(); } #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }

Compilation message (stderr)

biochips.cpp: In function 'void solve()':
biochips.cpp:32:9: warning: variable 'root' set but not used [-Wunused-but-set-variable]
   32 |     int root = 0;
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...