QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425912#8720. BFS 序 0blue-phantomRE 1ms6252kbC++141.0kb2024-05-30 18:54:062024-05-30 18:54:07

Judging History

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

  • [2024-05-30 18:54:07]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:6252kb
  • [2024-05-30 18:54:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
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] < 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: 100
Accepted
time: 1ms
memory: 6252kb

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
Yes
No
No
No
No
No
No
Yes

result:

ok 10 token(s): yes count is 3, no count is 7

Test #2:

score: -100
Runtime Error

input:

300000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:


result: