QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559823 | #6638. Treelection | louhao088 | TL | 3ms | 9892kb | C++23 | 1.5kb | 2024-09-12 09:35:07 | 2024-09-12 09:35:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi pair<int,int>
#define pb push_back
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mp make_pair
#define lowbit(i) (i&(-i))
#define mid ((l+r)/2)
inline int read(){
int x=0;char ch=getchar();bool f=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f)x=-x;return x;
}
const int maxn=1e6+5,mod=1e9+9;
int x,y,n,m,res,T,cnt;
int g[maxn],sz[maxn],t[maxn];
vector<int>e[maxn];
void dfs(int x){
sz[x]=1;
for(auto i:e[x]){
dfs(i);sz[x]+=sz[i];
}
}
int dfs1(int x,int y){
if(t[x])return 0;
int u=-y;
for(auto i:e[x]){
int z=dfs1(i,y)+1;
u+=z;
}
return max(0,u);
}
bool check(int y){
if(dfs1(1,y)>0)return 0;
return 1;
}
void get(){
int l=1,r=n;
while(l<=r){
if(check(mid))res=mid,r=mid-1;
else l=mid+1;
}
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++)e[i].clear(),g[i]=sz[i]=t[i]=0;
for(int i=2;i<=n;i++)cin>>x,e[x].pb(i);
dfs(1);get();cnt=0;
for(int i=1;i<=n;i++)if(e[i].size()==res&&sz[i]==res+1)cnt++;
for(int i=1;i<=n;i++){
if(sz[i]-1>res)putchar('1');
else if(sz[i]-1<res)putchar('0');
else{
if(e[i].size()!=res)putchar('0');
else{
t[i]=1;
if(dfs1(1,res-1)>0)putchar('0');
else putchar('1');
t[i]=0;
}
}
}puts("");
}
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cin>>T;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 9892kb
input:
2 4 1 2 3 5 1 1 2 2
output:
1100 10000
result:
ok 2 lines
Test #2:
score: -100
Time Limit Exceeded
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...