Submission #796366

# Submission time Handle Problem Language Result Execution time Memory
796366 2023-07-28T10:25:36 Z SlavicG Cat in a tree (BOI17_catinatree) C++17
0 / 100
2 ms 4948 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
const int N = 2e5 + 5;
vector<int> adj[N];
int cnt[N], n, d;

void dfs(int u, int par, int dist) {
	++cnt[dist % d];
	for(int v: adj[u]) {
		if(v == par) continue;
		dfs(v, u, dist + 1);
	}
}

void solve() {
	cin >> n >> d;
	for(int i = 1; i < n; ++i) {
		int x; cin >> x;
		adj[x].pb(i);
		adj[i].pb(x);
	}
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) cnt[j] = 0;
		dfs(i, -1, 0);
		ans = max(ans, cnt[0]);
	}
	cout << ans << '\n';
}

int32_t main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}
/*
4 3
0
0
1

3 1000
0
0
*/
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -