QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602914 | #8720. BFS 序 0 | UESTC_xxx# | WA | 2522ms | 59624kb | C++20 | 1.6kb | 2024-10-01 13:29:52 | 2024-10-01 13:29:54 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
int n,fa[30][300005],d[300005],q,p0,m,c[500005],flag,t[300005],tot,b[300005],a[300005];
vector<int>e[300005],g[300005];
bool ins[300005],vis[300005];
void dfs(int u){
for(int i=0;i<e[u].size();++i){
int v=e[u][i];
d[v]=d[u]+1;
dfs(v);
}
}
int lca(int x,int y){
if(d[x]<d[y]) swap(x,y);
for(int i=20;i>=0;--i) if(d[fa[i][x]]>=d[y]) x=fa[i][x];
if(x==y) return x;
for(int i=20;i>=0;--i) if(fa[i][x]!=fa[i][y]) x=fa[i][x],y=fa[i][y];
return fa[0][x];
}
void dfs0(int u){
ins[u]=vis[u]=1;
for(int i=0;i<g[u].size();++i){
int v=g[u][i];
if(ins[v]) flag=1;
if(!vis[v]) dfs0(v);
}
ins[u]=0;
}
int main(){
scanf("%d",&n);
for(int i=2;i<=n;++i){
scanf("%d",&fa[0][i]);
e[fa[0][i]].push_back(i);
}
scanf("%d",&q);
d[1]=1;
dfs(1);
for(int i=1;i<=22;++i) for(int j=1;j<=n;++j) fa[i][j]=fa[i-1][fa[i-1][j]];
while(q--){
scanf("%d",&m);
if(m==1){
printf("Yes\n");
continue;
}
flag=p0=tot=0;
for(int j=1;j<=m;++j){
scanf("%d",&a[j]);
if(d[a[j]]<d[a[j-1]]||a[j]==a[j-1]) flag=1;
}
for(int j=1;j<m;++j){
int x=a[j],y=a[j+1];
if(d[x]!=d[y]) continue;
for(int k=20;k>=0;--k) if(fa[k][x]!=fa[k][y]) x=fa[k][x],y=fa[k][y];
tot++,b[tot]=x,tot++,b[tot]=y;
g[x].push_back(y);
}
for(int j=1;j<=tot;++j){
if(vis[b[j]]) continue;
dfs0(b[j]);
}
if(flag) printf("No\n");
else printf("Yes\n");
for(int j=1;j<=tot;++j){
g[b[j]].clear();
vis[b[j]]=0;
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 38716kb
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: 2522ms
memory: 59624kb
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 No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...
result:
wrong answer expected YES, found NO [33rd token]