QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#416904 | #8720. BFS 序 0 | Hazer | WA | 159ms | 17472kb | C++17 | 1.1kb | 2024-05-22 10:36:41 | 2024-05-22 10:36:43 |
Judging History
answer
#include <bits/stdc++.h>
#define MAXN 300005
using namespace std;
int n,fa[MAXN],x,depth[MAXN],q,m;
vector<int>sons[MAXN];
void calc_depth(int x,int d) {
depth[x]=d;
for (int i=0;i<sons[x].size();i++)
calc_depth(sons[x][i],d+1);
return;
}
int seq[MAXN],top,pos[MAXN];
int main() {
cin>>n;
for (int i=2;i<=n;i++)
cin>>fa[i],sons[fa[i]].push_back(i);
calc_depth(1,0);
cin>>q;
for (int i=1;i<=q;i++) {
cin>>m;
top=0;
int maxpos;
bool flag=true;
for (int j=1;j<=m;j++) {
cin>>x;
if (pos[x]!=0) flag=false;
if (top==0) {
seq[++top]=x;
pos[x]=top;
maxpos=0;
} else if (depth[x]>depth[seq[top]]) {
seq[++top]=x;
pos[x]=top;
maxpos=0;
} else if (depth[x]==depth[seq[top]]) {
if (!pos[fa[x]]) {
seq[++top]=x;
pos[x]=top;
} else if (pos[fa[x]]>=maxpos) {
seq[++top]=x;
pos[x]=top;
maxpos=pos[fa[x]];
} else flag=false;
} else flag=false;
}
if (flag) cout<<"Yes\n";
else cout<<"No\n";
for (int i=1;i<=top;i++)
pos[seq[i]]=0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13704kb
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: 159ms
memory: 17472kb
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]