QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#640309#8551. DFS Order 5lvkaiyi0811WA 173ms11888kbC++201000b2024-10-14 10:52:212024-10-14 10:52:23

Judging History

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

  • [2024-10-14 10:52:23]
  • 评测
  • 测评结果:WA
  • 用时:173ms
  • 内存:11888kb
  • [2024-10-14 10:52:21]
  • 提交

answer

#include<bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long ll;
const ll _=1e5+5;
ll n,m,q,x,y,t,b[_],c[_],dfn[_],sz[_],dep[_],d[18][_],e[_],i,j;bool f[_];vector<ll>E[_];
inline void p1(ll x,ll fa){
	d[0][t]=e[x]=fa;dfn[x]=++t;sz[x]=1;
	for(ll y:E[x])if(y!=fa)dep[y]=dep[x]+1,p1(y,x),sz[x]+=sz[y];
}
inline ll p2(ll x,ll y){return dep[x]<dep[y]?x:y;}
inline ll p3(ll x,ll y){
	if(x==y)return x;x=dfn[x];y=dfn[y];if(x>y)swap(x,y);
	ll t=__lg(y-x);return p2(d[t][x],d[t][y-(1<<t)]);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>q;
	for(i=1;i<n;i++)cin>>x>>y,E[x].eb(y),E[y].eb(x);
	p1(1,0);
	for(i=1;i<18;i++)for(j=1;j<=n-(1<<i);j++)
		d[i][j]=p2(d[i-1][j],d[i-1][j+(1<<(i-1))]);
	while(q--){
		cin>>m>>x;t=1;b[1]=x;c[1]=0;
		memset(f,0,sizeof(f));
		for(i=1;i<m;i++){
			cin>>y;
			if(p3(x,y)!=e[y])break;
			for(;t&&dep[b[t]]>=dep[x];t--)if(i<c[t]+sz[b[t]])break;
			b[++t]=x=y;c[t]=i;
		}
		cout<<(i<m?"No\n":"Yes\n");
		while(++i<m)cin>>y;
	}
}

詳細信息

Test #1:

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

input:

6 7
1 2
1 3
2 4
3 5
2 6
2 4 1
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
6 1 2 6 4 3 5

output:

No
No
Yes
No
No
Yes
Yes

result:

ok 7 tokens

Test #2:

score: -100
Wrong Answer
time: 173ms
memory: 11888kb

input:

10 100000
7 2
1 7
7 10
8 6
8 7
1 3
4 5
9 5
5 8
8 8 9 7 2 8 1 6 1
4 8 3 5 2
6 7 10 3 9 9 1
1 1
8 10 3 2 9 3 8 7 3
7 5 6 2 8 5 9 1
6 3 4 6 2 1 3
5 8 9 2 4 9
1 3
2 1 5
5 8 5 1 7 9
10 5 2 9 2 6 4 10 6 3 8
3 4 5 8
2 8 4
9 4 10 1 2 4 3 3 6 3
1 3
6 1 1 6 8 3 1
3 7 3 2
3 9 1 5
4 3 7 8 10
9 4 2 3 10 2 5 4 3 ...

output:

No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
N...

result:

wrong answer 20th words differ - expected: 'No', found: 'Yes'