QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425921#8720. BFS 序 0blue-phantomWA 3ms11476kbC++141.2kb2024-05-30 19:01:002024-05-30 19:01:00

Judging History

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

  • [2024-05-30 19:01:00]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11476kb
  • [2024-05-30 19:01:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=300005;
int n, q, m, temp, depth[maxn], a[maxn];
vector<int> e[maxn];
void dfs(int p,int pre)
{
    depth[p] = depth[pre] + 1;
    for (int i: e[p])
        if(i!=pre)
            dfs(i, p);
}
bool judge()
{
    for (int i = 1; i <= m; i++)
    {
        if (a[i] < 1 || a[i] > n)
            return 0;
        if (depth[a[i]] < depth[a[i-1]])
            return 0;
    }
    sort(a+1,a+1+m);
    for (int i = 1; i <= m; i++)
    {
        if (a[i] == a[i-1])
            return 0;
    }
    return 1;
}
int main()
{
    scanf("%d",&n);
    for (int i = 2; i <= n; i++)
    {
        scanf("%d",&temp);
        e[i].emplace_back(temp);
        e[temp].emplace_back(i);
    }
    dfs(1, 0);
    // for (int i = 1; i <= n; i++)
    // {
    //     printf("%d ",depth[i]);
    // }
    // printf("\n");
    // return 0;
    scanf("%d", &q);
    while (q--)
    {
        scanf("%d",&m);
        for (int i = 1; i <= m; i++)
        {
            scanf("%d",a + i);
            a[i]=depth[a[i]];
        }
        if (judge())
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 11476kb

input:

6
1 1 3 2 4
10
4 3 6 2 5
1 4
3 2 4 5
5 2 5 4 6 3
3 1 4 2
3 5 6 3
5 4 5 2 6 1
4 4 3 2 5
4 4 6 2 3
3 3 2 6

output:

No
Yes
No
No
Yes
No
No
No
No
No

result:

wrong answer expected YES, found NO [3rd token]