Submission #535803

# Submission time Handle Problem Language Result Execution time Memory
535803 2022-03-11T10:05:38 Z ngpin04 Cat in a tree (BOI17_catinatree) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define ALL(x) (x).begin(), (x).end() 
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
const int N = 1505
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);

vector <int> adj[N];

int dp[N][N];
int n,d;

void dfs1(int u) {
	for (int v : adj[u])
		dfs1(v);

	dp[u][0] = 1;
	for (int v : adj[u])
		dp[u][0] += dp[v][d - 1];


	for (int i = 1; i <= d; i++) {
		int mx = 0;
		for (int v : adj[u]) {
			if (i <= (d >> 1)) {
				dp[u][i] += dp[v][d - i - 1];
				maxi(mx, dp[v][i - 1] - dp[v][d - i - 1]);
			} else {
				dp[u][i] += dp[v][i - 1];
			}
		}
		dp[u][i] += mx;
	}
			
	for (int i = d - 1; i >= 0; i--)
		maxi(dp[u][i], dp[u][i + 1]);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef ONLINE_JUDGE
	// freopen(TASK".inp","r",stdin);
	// freopen(TASK".out","w",stdout);
	#endif
	cin >> n >> d;
	for (int i = 2; i <= n; i++) {
		int j; cin >> j;
		j++;
		adj[j].push_back(i);
	}

	if (n <= 1500 && d <= 1500) {
		dfs1(1);
		int ans = 0;
		for (int i = 0; i <= d; i++)
			maxi(ans, dp[1][i]);

		cout << ans;
	}

	return 0;
}

Compilation message

catinatree.cpp:15:1: error: expected ',' or ';' before 'const'
   15 | const int oo = 1e9;
      | ^~~~~