# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
673294 | 2022-12-20T05:59:21 Z | Baytoro | 바이오칩 (IZhO12_biochips) | C++17 | 550 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; 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); tmp.assign(m+1,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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5076 KB | Output is correct |
2 | Correct | 2 ms | 5076 KB | Output is correct |
3 | Correct | 3 ms | 5332 KB | Output is correct |
4 | Correct | 21 ms | 40544 KB | Output is correct |
5 | Correct | 23 ms | 45120 KB | Output is correct |
6 | Correct | 25 ms | 45004 KB | Output is correct |
7 | Runtime error | 372 ms | 524288 KB | Execution killed with signal 9 |
8 | Runtime error | 373 ms | 524288 KB | Execution killed with signal 9 |
9 | Runtime error | 494 ms | 524288 KB | Execution killed with signal 9 |
10 | Runtime error | 550 ms | 524288 KB | Execution killed with signal 9 |