QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#415753 | #8720. BFS 序 0 | ANIG# | WA | 162ms | 25996kb | C++14 | 856b | 2024-05-21 09:32:10 | 2024-05-21 09:32:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e5+5;
int n,m,qs,fa[N],p[N],dep[N],wzx[N],wzd[N];
vector<int>e[N];
bool solve(){
for(int i=2;i<=m;i++)if(dep[p[i]]<dep[p[i-1]])return 0;
int mn=1e9,idx=0;
for(int i=m;i>=1;i--){
if(dep[p[i]]!=dep[p[i+1]]&&i<m){
}else if(i<m){
if(wzd[p[i]]&&wzd[p[i]]>mn)return 0;
}
if(wzx[p[i]])mn=min(mn,wzx[p[i]]);
wzd[fa[p[i]]]=max(wzd[fa[p[i]]],--idx);
wzx[fa[p[i]]]=min(wzx[fa[p[i]]],idx);
}
return 1;
}
void dfs(int x){
for(auto c:e[x]){
dep[c]=dep[x]+1;
dfs(c);
}
}
signed main(){
cin>>n;
for(int i=2;i<=n;i++)cin>>fa[i],e[fa[i]].push_back(i);
dfs(1);
cin>>qs;
while(qs--){
cin>>m;
for(int i=1;i<=m;i++)cin>>p[i],wzx[p[i]]=wzd[p[i]]=wzx[fa[p[i]]]=wzd[fa[p[i]]]=0;
if(solve())puts("Yes");
else puts("No");
}
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 18304kb
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: 162ms
memory: 25996kb
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:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong answer expected NO, found YES [1st token]