QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#416908#8720. BFS 序 0HazerWA 155ms17268kbC++171.1kb2024-05-22 10:46:302024-05-22 10:46:30

Judging History

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

  • [2024-05-22 10:46:30]
  • 评测
  • 测评结果:WA
  • 用时:155ms
  • 内存:17268kb
  • [2024-05-22 10:46:30]
  • 提交

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=pos[fa[x]];
			} 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 j=1;j<=top;j++)
			pos[seq[j]]=0;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 13920kb

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: 155ms
memory: 17268kb

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]