QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425912 | #8720. BFS 序 0 | blue-phantom | RE | 1ms | 6252kb | C++14 | 1.0kb | 2024-05-30 18:54:06 | 2024-05-30 18:54:07 |
Judging History
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...