답안 #435955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435955 2021-06-24T02:34:02 Z cgiosy 바이오칩 (IZhO12_biochips) C++17
컴파일 오류
0 ms 0 KB
// gs14004's code test
#include <bits/stdc++.h>
using namespace std;

int n,m,inp[200005];

int piv,sz[200005],a[200005];
vector<int> g[200005];
int root;

int dfs(int x){
    int num = ++piv;
    a[num] = inp[x];
    sz[num] = 1;
    for(int &i : g[x]){
        sz[num] += dfs(i);
    }
    return sz[num];
}
 
int dp[2][200005];

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	int W[N+1];
	for(int i=1; i<=N; i++) {
		int p;
		cin>>p>>W[i];inp[i]=W[i];
		if(p) g[p].push_back(i);
		else root=r=i;
	}
    dfs(root);
    for (int i=1; i<=m; i++) {
        dp[i%2][n+1] = -1e9;
        for (int j=n; j; j--) {
            dp[i%2][j] = max(dp[i%2][j+1],dp[(i-1)%2][j+sz[j]] + a[j]);
        }
    }
	cout<<dp[m%2][1]<<'\n';
}

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:26:8: error: 'N' was not declared in this scope
   26 |  int W[N+1];
      |        ^
biochips.cpp:29:11: error: 'W' was not declared in this scope
   29 |   cin>>p>>W[i];inp[i]=W[i];
      |           ^
biochips.cpp:31:13: error: 'r' was not declared in this scope
   31 |   else root=r=i;
      |             ^