QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#416902#8720. BFS 序 0HazerWA 148ms17488kbC++171.1kb2024-05-22 10:35:122024-05-22 10:35:13

Judging History

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

  • [2024-05-22 10:35:13]
  • 评测
  • 测评结果:WA
  • 用时:148ms
  • 内存:17488kb
  • [2024-05-22 10:35:12]
  • 提交

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;
		bool flag=true;
		for (int j=1;j<=m;j++) {
			cin>>x;
			if (pos[x]!=0) flag=false;
			int maxpos;
			if (top==0) {
				seq[++top]=x;
				pos[x]=top;
			} 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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 13868kb

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: 148ms
memory: 17488kb

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]