QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209991#6638. TreelectionkkioWA 168ms45568kbC++171.4kb2023-10-10 21:14:442023-10-10 21:14:44

Judging History

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

  • [2023-10-10 21:14:44]
  • 评测
  • 测评结果:WA
  • 用时:168ms
  • 内存:45568kb
  • [2023-10-10 21:14:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int n,p[maxn],f[maxn];
vector<int> G[maxn];
int L;
void dfs(int u,int fa)
{
    int sum=0;
    for(int v:G[u])
        if(v!=fa)
            dfs(v,u),sum+=f[v];
    f[u]=(u!=1)+max(0,sum-L);
}
int tag[maxn],siz[maxn],S[maxn];
void sdfs(int u,int fa)
{
    siz[u]=0;
    tag[u]=min(tag[u],f[u]);
    for(int v:G[u])
        if(v!=fa)
        {
            sdfs(v,u);
            tag[v]=tag[u];
            siz[u]+=siz[v];
        }
    S[u]=siz[u];
    siz[u]++;
}
char ans[maxn];
void solve()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)G[i].clear();
    for(int i=2;i<=n;i++)
        scanf("%d",&p[i]),G[p[i]].push_back(i),G[i].push_back(p[i]);
    int l=1,r=n,mid,z=n;
    while(l<=r)
    {
        mid=l+r>>1;
        //printf("%d\n",mid);
        L=mid;
        dfs(1,0);
        if(f[1]==0)z=mid,r=mid-1;
        else l=mid+1;
    }
    L=z-1;
    //printf("%d\n",z);
    dfs(1,0);
   // for(int i=1;i<=n;i++)printf("%d ",f[i]);putchar('\n');
    for(int i=1;i<=n;i++)tag[i]=1e9;
    sdfs(1,0);
    //for(int i=1;i<=n;i++)printf("%d ",S[i]);putchar('\n');
    for(int i=1;i<=n;i++)
        if(S[i]>z||(S[i]==z&&tag[i]&&f[1]==1))ans[i]='1';
        else ans[i]='0';
    for(int i=1;i<=n;i++)putchar(ans[i]);putchar('\n');
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 38500kb

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: 168ms
memory: 45568kb

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'