QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#559811#6638. Treelectionlouhao088WA 123ms16412kbC++231.5kb2024-09-12 09:29:452024-09-12 09:29:45

Judging History

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

  • [2024-09-12 09:29:45]
  • 评测
  • 测评结果:WA
  • 用时:123ms
  • 内存:16412kb
  • [2024-09-12 09:29:45]
  • 提交

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;g[x]=1;
	for(auto i:e[x]){
		dfs(i);sz[x]+=sz[i];
		if(sz[i]!=1)g[x]=0;
	}
	if(sz[x]==1)g[x]=0;
}
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(g[i]&&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(!g[i])putchar('0');
			else if(cnt>=2)putchar('0');
			else{
				t[i]=1;
				if(dfs1(1,res-1)>0)putchar('0');
				else putchar('1');
			}
		}
	}puts("");
}
signed main(){
    std::ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>T;
	while(T--)solve();
	
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 9712kb

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: 123ms
memory: 16412kb

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'