답안 #435929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435929 2021-06-24T01:17:10 Z cgiosy 바이오칩 (IZhO12_biochips) C++17
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
using namespace std;

void mx(int&a, int b) { a=max(a, b); }
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int N, K, r;
	cin>>N>>K;
	int D[N+1][500], F[N+1], G[N+1]{}, W[N+1];
	for(int i=1; i<=N; i++) {
		int p;
		cin>>p>>W[i];
		if(p) F[i]=G[p], G[p]=i;
		else r=i;
	}
	function<int(int)> dfs=[&](int i) {
		int n=0;
		for(int e=G[i]; e; e=F[e]) {
			int m=dfs(e), j=min(n+m, K);
			while(n<j) D[i][n++]=-1e9;
			while(--j) for(int k=min(m, j); k--;)
				mx(D[i][j], D[i][j-k-1]+D[e][k]);
			for(int k=0; k<m; k++) mx(D[i][k], D[e][k]);
		}
		if(n) mx(D[i][0], W[i]);
		else D[i][n++]=W[i];
		return n;
	};
	cout<<D[r][dfs(r)-1]<<'\n';
}

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:29:24: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |  cout<<D[r][dfs(r)-1]<<'\n';
      |                        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -