Submission #827435

#TimeUsernameProblemLanguageResultExecution timeMemory
827435MasterTasterBiochips (IZhO12_biochips)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define xx first #define yy second #define pb push_back #define MAXN 22//200010 #define MAXM 22//510 #define MAXX 100000010 using namespace std; int n, m, p[MAXN], w[MAXN], dp[MAXN][MAXM]; bool bio[MAXN]; vector<int> g[MAXN]; void merge(int u, int v) { int pomoc[MAXM]; for (int i=0; i<=m; i++) pomoc[i]=dp[u][i]; for (int i=0; i<=m; i++) for (int j=0; i+j<=m; j++) if (i+j<=m) pomoc[i+j]=max(pomoc[i+j], dp[u][i]+dp[v][j]); for (int i=0; i<=m; i++) dp[u][i]=pomoc[i]; } void dfs(int u) { bio[u]=true; for (int i=0; i<=m; i++) dp[u][i]=-MAXX; dp[u][0]=0; for (auto v:g[u]) { if (!bio[v]) { dfs(v); } } for (auto v:g[u]) { if (v==p[u]) continue; merge(u, v); } dp[u][1]=max(dp[u][1], w[u]); ///cout<<u<<":"<<endl; ///for (int i=0; i<=m; i++) cout<<dp[u][i]<<" "; ///cout<<endl; } int main(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif cin>>n>>m; int koren=1; for (int i=1; i<=n; i++) { cin>>p[i]>>w[i]; if (p[i]==0) { koren=i; continue; } g[p[i]].pb(i); g[i].pb(p[i]); } dfs(koren); cout<<dp[koren][m]; } ///-10 bar

Compilation message (stderr)

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