QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114400 | #6638. Treelection | jeffqi | WA | 73ms | 4724kb | C++23 | 1.2kb | 2023-06-22 01:02:28 | 2023-06-22 01:02:31 |
Judging History
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'