QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#415753#8720. BFS 序 0ANIG#WA 162ms25996kbC++14856b2024-05-21 09:32:102024-05-21 09:32:13

Judging History

你现在查看的是最新测评结果

  • [2024-05-21 10:04:17]
  • hack成功,自动添加数据
  • (/hack/624)
  • [2024-05-21 09:32:13]
  • 评测
  • 测评结果:WA
  • 用时:162ms
  • 内存:25996kb
  • [2024-05-21 09:32:10]
  • 提交

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");
	}
}

Details

Tip: Click on the bar to expand more detailed information

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]