QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212176#6638. Treelectionsinsop90WA 1ms9860kbC++141009b2023-10-13 10:46:422023-10-13 10:46:42

Judging History

你现在查看的是最新测评结果

  • [2023-10-13 10:46:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9860kb
  • [2023-10-13 10:46:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int T, f[maxn], fa[maxn], sz[maxn], n, vis[maxn];
bool check(int x) {
	for(int i = 1;i <= n;i++) f[i] = 0;
	for(int i = n;i >= 1;i--) {
		f[i] = max(0, f[i] - x);
		if(fa[i]) f[fa[i]] += f[i] + 1;
	}
	return (f[1] > 0);
}
void solve() {
	cin >> n;
	for(int i = 2;i <= n;i++) cin >> fa[i];
	for(int i = n;i >= 1;i--) sz[fa[i]] += sz[i] + 1;
	int l = 1, r = n, res = 1;
	while(l <= r) {
		int mid = (l + r) >> 1;
		check(mid);
//		cout << mid << " " << f[1] << endl;
		if(!check(mid)) r = mid - 1;
		else l = mid + 1, res = mid;
	}
//	cout << res << endl;
	check(res);
	if(f[1] == 1) {
		vis[1] = 1;
		for(int i = 2;i <= n;i++) vis[i] = (vis[fa[i]] && f[i]);
	}
	for(int i = 1;i <= n;i++) {
		if(sz[i] > res + 1 || (sz[i] == res + 1 && vis[i])) cout << 1;
		else cout << 0;
	}
	cout << '\n';
}
int main() {
//	ios::sync_with_stdio(0);
//	cin.tie(0), cout.tie(0);
	cin >> T;
	while(T --) solve();
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9860kb

input:

2
4
1 2 3
5
1 1 2 2

output:

1000
11000

result:

wrong answer 1st lines differ - expected: '1100', found: '1000'