QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549827#6638. TreelectionpigstdWA 0ms9832kbC++201.4kb2024-09-06 21:50:122024-09-06 21:50:12

Judging History

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

  • [2024-09-06 21:50:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9832kb
  • [2024-09-06 21:50:12]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define vi vector<int>
#define vpi vector<pii>
#define all(x) (x).begin(),(x).end()
using namespace std;

inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

const int M=1e6+10;
int n,sz[M],fa[M],deg[M],f[M];

void solve()
{
    n=read();
    for (int i=1;i<=n;i++)deg[i]=0,sz[i]=1;
    for (int i=2;i<=n;i++)fa[i]=read(),deg[fa[i]]++;
    for (int i=n;i>=2;i--)sz[fa[i]]+=sz[i];
    int tl=1,tr=n,ans=-1;
    while(tl<=tr)
    {
        int Mid=(tl+tr)>>1;
        for (int i=1;i<=n;i++)f[i]=deg[i];
        for (int i=n;i>=2;i--)
            if (f[i]>Mid)f[fa[i]]+=f[i]-Mid,f[i]=Mid;
        if (f[1]<=Mid)ans=Mid,tr=Mid-1;
        else tl=Mid+1;
    }
    for (int i=1;i<=n;i++)f[i]=deg[i];
    ans--;
    int cnt=0;
    for (int i=n;i>=2;i--)
        if (f[i]>=ans)f[fa[i]]+=f[i]-ans,f[i]=ans;
    for (int i=1;i<=n;i++)
    {
        if (sz[i]-1>ans)cout<<"1";
        else if (sz[i]-1<ans)cout<<"0";
        else if (f[i]==ans+1&&deg[i]==ans+1)cout<<"1";
        else cout<<"0";
    }
    cout<<"\n";
}

signed main()
{
    int T=read();
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
1 2 3
5
1 1 2 2

output:

1110
11000

result:

wrong answer 1st lines differ - expected: '1100', found: '1110'