# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673295 | 2022-12-20T06:00:26 Z | Baytoro | Biochips (IZhO12_biochips) | C++17 | 537 ms | 524288 KB |
#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]; vector<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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5076 KB | Output is correct |
2 | Correct | 4 ms | 5076 KB | Output is correct |
3 | Correct | 3 ms | 5332 KB | Output is correct |
4 | Correct | 20 ms | 40532 KB | Output is correct |
5 | Correct | 25 ms | 45012 KB | Output is correct |
6 | Correct | 24 ms | 45012 KB | Output is correct |
7 | Runtime error | 365 ms | 524288 KB | Execution killed with signal 9 |
8 | Runtime error | 371 ms | 524288 KB | Execution killed with signal 9 |
9 | Runtime error | 511 ms | 524288 KB | Execution killed with signal 9 |
10 | Runtime error | 537 ms | 524288 KB | Execution killed with signal 9 |