QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602621 | #8720. BFS 序 0 | frs# | WA | 55ms | 21288kb | C++14 | 1.5kb | 2024-10-01 11:17:57 | 2024-10-01 11:17:57 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int N = 5e5 + 5;
int n, qr, m, cnt[N], a[N];
bool f[N];
vector<int> ve[N];
struct qnode{
int id, d;
qnode(int id1 = 0, int d1 = 0){
id = id1;
d = d1;
}
}tp;
queue<qnode> q;
int main(){
scanf("%d", &n);
int u;
for(int i = 2; i <= n; i++){
scanf("%d", &u);
ve[u].push_back(i);
}
q.push(qnode(1, 1));
while(!q.empty()){
tp = q.front();
q.pop();
cnt[tp.id] = tp.d;
int sz = ve[tp.id].size();
for(int i = 0; i < sz; i++){
q.push(qnode(ve[tp.id][i], tp.d + 1));
}
}
scanf("%d", &qr);
while(qr--){
scanf("%d", &m);
bool flag = 1;
for(int i = 1; i <= m; i++){
scanf("%d", &a[i]);
f[a[i]] = 0;
if(a[i] < 1 || a[i] > n){
flag = 0;
}
}
f[a[1]] = 1;
for(int i = 2; i <= m; i++){
if(flag == 0) break;
if(cnt[a[i]] < cnt[a[i - 1]]){
flag = 0;
break;
}
if(f[a[i]]){
flag = 0;
break;
}
f[a[i]] = 1;
}
if(!flag) printf("No\n");
else printf("Yes\n");
}
return 0;
}
/*
6
1 1 3 2 4
10
4 3 6 2 5
1 4
3 4 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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 18716kb
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
Wrong Answer
time: 55ms
memory: 21288kb
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:
No Yes Yes Yes No No No No No No Yes Yes No Yes No Yes Yes Yes No No No No Yes No No Yes No No No No Yes Yes Yes No No Yes No No No No No No No Yes No Yes No Yes No No No No Yes Yes Yes No No Yes No No No No No Yes Yes No No No No No Yes Yes No Yes No No No Yes No No Yes No No Yes Yes Yes Yes No No ...
result:
wrong answer expected NO, found YES [87th token]