QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549831#6638. TreelectionpigstdWA 1ms9796kbC++201.5kb2024-09-06 21:51:522024-09-06 21:51:52

Judging History

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

  • [2024-09-06 21:51:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9796kb
  • [2024-09-06 21:51:52]
  • 提交

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;
    cout<<f[1]<<' '<<ans<<'\n';
    for (int i=1;i<=n;i++)
    {
        if (sz[i]-1>ans+1)cout<<"1";
        else if (sz[i]-1<ans+1)cout<<"0";
        else if (f[1]==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: 1ms
memory: 9796kb

input:

2
4
1 2 3
5
1 1 2 2

output:

3 0
1100
3 1
10000

result:

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