QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114813 | #6638. Treelection | 1kri | WA | 180ms | 58852kb | C++14 | 1.2kb | 2023-06-23 17:14:57 | 2023-06-23 17:15:02 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int read(){
int x=0;
char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x;
}
int t,n;
vector<int> e[1000005];
int sz[1000005],f[1000005];
void dfs1(int now,int x){
sz[now]=1;
f[now]=0;
for (int i=0;i<(int)e[now].size();i++){
dfs1(e[now][i],x);
sz[now]+=sz[e[now][i]];
f[now]+=f[e[now][i]];
}
f[now]=max(f[now]-x,0);
f[now]++;
return;
}
int ans[200005];
void dfs2(int now,int x,int s,int fg){
if (s<0)fg=0;
if (sz[now]-1<x)ans[now]=0;
if (sz[now]-1>x)ans[now]=1;
if (sz[now]-1==x)ans[now]=fg;
int c=0;
for (int i=0;i<(int)e[now].size();i++)c+=f[e[now][i]];
for (int i=0;i<(int)e[now].size();i++)dfs2(e[now][i],x,s+x-1-(c-f[e[now][i]]+1),fg);
return;
}
int main(){
t=read();
while(t--){
n=read();
for (int i=2;i<=n;i++){
int p=read();
e[p].push_back(i);
}
int l=1,r=n,x=n;
while(l<=r){
int mid=(l+r)/2;
dfs1(1,mid);
if (f[1]==1)x=mid,r=mid-1;
else l=mid+1;
}
dfs1(1,x-1);
dfs2(1,x,0,1);
for (int i=1;i<=n;i++)putchar('0'+ans[i]);
putchar('\n');
for (int i=1;i<=n;i++)e[i].clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 30204kb
input:
2 4 1 2 3 5 1 1 2 2
output:
1100 10000
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 126ms
memory: 33924kb
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:
ok 10 lines
Test #3:
score: -100
Wrong Answer
time: 180ms
memory: 58852kb
input:
1 1000000 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'