QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#416894#8720. BFS 序 0HazerWA 158ms17596kbC++171.0kb2024-05-22 10:32:012024-05-22 10:32:01

Judging History

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

  • [2024-05-22 10:32:01]
  • 评测
  • 测评结果:WA
  • 用时:158ms
  • 内存:17596kb
  • [2024-05-22 10:32:01]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 158ms
memory: 17596kb

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]