QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549756#6638. TreelectionpigstdWA 54ms12332kbC++201.4kb2024-09-06 21:07:162024-09-06 21:07:17

Judging History

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

  • [2024-09-06 21:07:17]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:12332kb
  • [2024-09-06 21:07:16]
  • 提交

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];
    int cnt=0;
    for (int i=n;i>=2;i--)
        if (f[i]>=ans)f[fa[i]]+=f[i]-ans,f[i]=ans,cnt++;
    if (f[1]==ans)cnt++;
    for (int i=1;i<=n;i++)
    {
        if (sz[i]-1>ans)cout<<"1";
        else if (sz[i]-1<ans)cout<<"0";
        else if (cnt==1&&f[i]==ans)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: 100
Accepted
time: 0ms
memory: 9832kb

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: 54ms
memory: 12332kb

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'