QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114400#6638. TreelectionjeffqiWA 73ms4724kbC++231.2kb2023-06-22 01:02:282023-06-22 01:02:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-22 01:02:31]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:4724kb
  • [2023-06-22 01:02:28]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
using namespace std;
namespace qiqi {
	void main() {
		int n;
		cin >> n;
		vi fa(n,-1);
		for (int i = 1; i < n; i++) {
			cin >> fa[i]; fa[i]--;
		}
		vi f(n);
		auto chk = [&](int k) {
			f.assign(n,0);
			for (int i = n-1; i > 0; i--) {
				f[fa[i]] += max(f[i]-k,0)+1;
			}
			return f[0] <= k;
		};
		int l = 0,r = n;
		while (r-l > 1) {
			int mid = l+((r-l)>>1);
			chk(mid) ? r = mid : l = mid;
		}
		chk(l);
		vi siz(n,1),can(n);
		for (int i = n-1; i > 0; i--) {
			siz[fa[i]] += siz[i];
		}
		can[0] = f[0] == r;
		for (int i = 1; i < n; i++) {
			can[i] = can[fa[i]]&(f[i] > 0);
		}
		for (int i = 0; i < n; i++) {
			cout << (siz[i]-1 > r || (siz[i]-1 == r && can[i]));
		}
		cout << '\n';
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T; cin >> T;
	while (T--) qiqi::main();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3464kb

input:

2
4
1 2 3
5
1 1 2 2

output:

1100
10000

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 73ms
memory: 4724kb

input:

10
100000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '111111111111111111111111111111...0000000000000000000000000000000', found: '111111111111111111111111111111...0000000000000000000000000000000'