QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201609#6638. Treelectionucup-team870WA 0ms35544kbC++171.4kb2023-10-05 15:27:472023-10-05 15:27:47

Judging History

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

  • [2023-10-05 15:27:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:35544kb
  • [2023-10-05 15:27:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
const int N=1e6+6;
int fa[N],res[N],dp[N],V,sz[N],ok[N];
vi tu[N];
void dfs(int now){
    int sum=0; sz[now]=1;
    for(int son:tu[now]){
        dfs(son); sum+=dp[son]; sz[now]+=sz[son];
    }
    dp[now]=(now!=1)+max(0,V-sum);
}
void slv(){
    int n; cin>>n;
    rep(i,1,n){
        tu[i].clear(); res[i]=0;
    }
    rep(i,2,n){
        cin>>fa[i]; tu[fa[i]].push_back(i);
    }
    int L=1,R=n-1;
    while(L<=R){
        V=L+R>>1; dfs(1);
        if(dp[1])L=V+1; 
        else R=V-1;
    }
    V=L-1; dfs(1); //assert(dp[1]);
    V=L;
    ok[1]=(dp[1]==1);
    // function <void(int)> dfs0=[&](int now){
    //     for(int son:tu[now]){

    //     }
    // };
    rep(i,2,n){
        ok[i]=(dp[i]>0 && ok[fa[i]]);
    }
    rep(i,1,n){
        int v=sz[i]-1;
        // cout<<v<<' ';
        if(v>V)res[i]=1;
        else if(v<V)res[i]=0;
        else{
            // if(dp[1]==1 && dp[i]==1)res[i]=1;
            if(ok[i])res[i]=1;
            else res[i]=0;
        }
    }
    rep(i,1,n)cout<<res[i]; cout<<'\n';
}
signed main(){
    IOS
    int T;cin>>T;
    while(T--)slv();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 35544kb

input:

2
4
1 2 3
5
1 1 2 2

output:

1100
11000

result:

wrong answer 2nd lines differ - expected: '10000', found: '11000'