Submission #673296

#TimeUsernameProblemLanguageResultExecution timeMemory
673296BaytoroBiochips (IZhO12_biochips)C++17
60 / 100
406 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define int long long #define endl '\n' #define cnt(x) __builtin_popcount(x) void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int INF=1e18,mod=998244353; int n,m; const int N=2e5+5; int a[N],sz[N]; int dp[N][505]; int tmp[505]; vector<int> g[N]; void dfs(int x, int p){ sz[x]=1; dp[x][0]=0; for(auto it: g[x]){ if(it==p) continue; dfs(it,x); for(int i=0;i<=m+1;i++) tmp[i]=0; for(int i=0;i<=min(sz[x],m);i++) for(int j=0;j<=min(m-i,sz[it]);j++) tmp[i+j]=max(tmp[i+j],dp[x][i]+dp[it][j]); sz[x]+=sz[it]; for(int i=1;i<=min(m,sz[x]);i++) dp[x][i]=tmp[i]; } dp[x][1]=max(dp[x][1],a[x]); } void solve(){ cin>>n>>m; int r=0; for(int i=1;i<=n;i++){ int p;cin>>p>>a[i]; if(!p)r=i; else{ g[p].pb(i); g[i].pb(p); } } dfs(r,r); cout<<dp[r][m]<<endl; } main(){ //fopn("newbarn"); ios; int T=1; //cin>>T; while(T--){ solve(); } }

Compilation message (stderr)

biochips.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main(){
      | ^~~~
biochips.cpp: In function 'void fopn(std::string)':
biochips.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
biochips.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...