Submission #921336

# Submission time Handle Problem Language Result Execution time Memory
921336 2024-02-03T17:49:32 Z penguin133 Cat in a tree (BOI17_catinatree) C++17
0 / 100
2 ms 5980 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, d;
vector <int> adj[200005];
pi mem[200005];

pi dp(int x, int par){
	vector <int> tmp;
	int cur = 0;
	for(auto i : adj[x]){
		if(i == par)continue;
		pi lmao = dp(i, x);
		tmp.push_back(lmao.se);
		cur += lmao.fi;
	}
	int in = 0;
	while((int)tmp.size() > in + 1 && tmp[in] + tmp[in + 1] + 2 < d)in++, cur--;
	int left = (in < (int)tmp.size() ? tmp[in] + 1 : d);
	if(left >= d)left -= d, cur++;
	//cout << x << ' ' << cur << ' ' << left << '\n';
	return mem[x] = {cur, left};
}

void solve(){
	cin >> n >> d;
	for(int i = 1; i < n; i++){
		int a; cin >> a; a++;
		adj[a].push_back(i + 1);
		adj[i + 1].push_back(a);
	}
	cout << dp(1, -1).fi << '\n';
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

catinatree.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5980 KB Output isn't correct
2 Halted 0 ms 0 KB -