Submission #1291208

#TimeUsernameProblemLanguageResultExecution timeMemory
1291208gramathegod바이오칩 (IZhO12_biochips)C++20
0 / 100
2 ms576 KiB
#include <bits/stdc++.h> using namespace std; const int N=2e5+5, M=505; vector<int>adj[N]; int dp[N][M], sz[N], val[N], n,m,root; void getsz(int i){ for (auto x:adj[i]){ getsz(x); sz[i]+=sz[x]; } if (adj[i].size()==0){ sz[i]=1; } } void dfs(int i){ int maxj=min(m,sz[i]); for (auto x:adj[i]){ dfs(x); int maxk=min(m,sz[x]); for (int j=maxj;j>=0;j--){ for (int k=min(maxk,j);k>=0;k--){ dp[i][j]=max(dp[i][j], dp[i][j-k]+dp[x][k]); } } } dp[i][1]=max(dp[i][1], val[i]); } int main() { freopen("d.in", "r", stdin); freopen("d.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m; for (int i=1;i<=n;i++){ int p;cin>>p>>val[i]; if (p==0){ root=i; } adj[p].push_back(i); } getsz(root); dfs(root); cout<<dp[root][m]; return 0; }

Compilation message (stderr)

biochips.cpp: In function 'int main()':
biochips.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen("d.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
biochips.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen("d.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...