QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#416906#8720. BFS 序 0HazerWA 158ms17656kbC++171.1kb2024-05-22 10:40:012024-05-22 10:40:02

Judging History

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

  • [2024-05-22 10:40:02]
  • 评测
  • 测评结果:WA
  • 用时:158ms
  • 内存:17656kb
  • [2024-05-22 10:40: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;
		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=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 j=1;j<=top;j++)
			pos[seq[j]]=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 17656kb

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]