QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425921 | #8720. BFS 序 0 | blue-phantom | WA | 3ms | 11476kb | C++14 | 1.2kb | 2024-05-30 19:01:00 | 2024-05-30 19:01:00 |
Judging History
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]