QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209110#6638. Treelectionc20230507WA 85ms5984kbC++141.0kb2023-10-10 10:16:052023-10-10 10:16:06

Judging History

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

  • [2023-10-10 10:16:06]
  • 评测
  • 测评结果:WA
  • 用时:85ms
  • 内存:5984kb
  • [2023-10-10 10:16:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const int INF=0x3f3f3f3f;
int t,n,fa[maxn],siz[maxn],dp[maxn],vis[maxn];
int check(int x){
    for(int i=1;i<=n;i++)dp[i]=0;
    for(int i=n;i>1;i--){
        dp[i]=max(dp[i]-x,0);
        dp[fa[i]]=dp[fa[i]]+dp[i]+1;
    }
    return dp[1]<=x;
}
int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=2;i<=n;i++)cin>>fa[i];
        for(int i=1;i<=n;i++)siz[i]=1;
        for(int i=n;i>1;i--)siz[fa[i]]+=siz[i];
        int l=1,r=n,ans;
        while(l<=r){
            int mid=(l+r)/2;
            if(check(mid))r=mid-1,ans=mid;
            else l=mid+1;
        }
        check(ans-1);
        if(dp[1]==ans){
            vis[1]=1;
            for(int i=2;i<=n;i++)if(vis[fa[i]]&&dp[i])vis[i]=1;
        }
        for(int i=1;i<=n;i++){
            if(siz[i]-1>ans||(siz[i]-1==ans&&vis[i]))cout<<1;
            else cout<<0;
        }
        cout<<"\n";
    }
    return 0;
}

詳細信息

Test #1:

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

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: 85ms
memory: 5984kb

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 5th lines differ - expected: '111111111111111111111111111111...0000000000000000000000000000000', found: '111111111111111111111111111111...0000000000000000000000000000000'