Submission #89376

#TimeUsernameProblemLanguageResultExecution timeMemory
89376VardanyanBiochips (IZhO12_biochips)C++14
0 / 100
889 ms400376 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200*1000+5; vector<int> g[N]; int X[N]; int n,m; int dp[N][505]; int knap[N][505]; int ans = 0; void dfs(int v,int p = -1){ dp[v][1] = X[v]; for(int i = 0;i<g[v].size();i++){ int to = g[v][i]; if(to == p) continue; dfs(to,v); } int cnt = 0; memset(knap,0,sizeof(knap)); for(int i = 0;i<g[v].size();i++){ if(g[v][i] == p) continue; cnt++; for(int x = m;x>=1;x--){ for(int y = x;y>=1;y--){ for(int pos = 0;pos<cnt;pos++){ knap[cnt][x] = max(knap[cnt][x],knap[pos][x-y]+dp[g[v][i]][y]); dp[g[v][i]][x] = max(dp[g[v][i]][x],knap[cnt][x]); if(x == m) ans = max(ans,dp[g[v][i]][x]); } } } } } int main(){ scanf("%d%d",&n,&m); int root; for(int i = 1;i<=n;i++){ int v,x; scanf("%d%d",&v,&x); X[i] = x; if(v == 0) { root = i; continue; } g[v].push_back(i); g[i].push_back(v); } dfs(root); printf("%d\n",ans); return 0; }

Compilation message (stderr)

biochips.cpp: In function 'void dfs(int, int)':
biochips.cpp:12:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
biochips.cpp:19:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
biochips.cpp: In function 'int main()':
biochips.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
biochips.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&v,&x);
         ~~~~~^~~~~~~~~~~~~~
biochips.cpp:47:8: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dfs(root);
     ~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...