WA90pts求助(玄关)
查看原帖
WA90pts求助(玄关)
1199534
ycy1124楼主2024/6/27 18:18
#include<bits/stdc++.h>
using namespace std;
long long ans[100001][3];
bool bj[100001][3];
int n,m,q,tot=0;
struct Node{
	int to,w;	
};
Node b[100001];
vector <Node> a[100001];
void work(int x){
	if(x/2>=1&&b[x].w<b[x/2].w){
		swap(b[x],b[x/2]);
		work(x/2);
	}
}
void work1(int x){
	if(b[x*2].w<b[x*2+1].w&&x*2+1<=tot&&b[x*2].w<b[x].w){
		swap(b[x*2],b[x]);
		work1(x*2);
	}
	else if(x*2+1<=tot&&b[x*2+1].w<b[x].w){
		swap(b[x*2+1],b[x]);
		work1(x*2+1);
	}
	else if(x*2+1>tot&&x*2<=tot&&b[x*2].w<b[x].w){
		swap(b[x*2],b[x]);
		work1(x*2);
	}
	else{
		return;
	}
}
void bfs(int i,int js){
	//printf("%d %d\n",i,js);
	if(bj[i][js%2+1]){
		return;
	}
	bj[i][js%2+1]=1;
	ans[i][js%2+1]=js;
	for(auto it:a[i]){
		if(!bj[it.to][(it.w+js)%2+1]){
			b[++tot].w=it.w+js;
			b[tot].to=it.to;
			work(tot); 
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=m;i++){
		int u,v,w=1;
		scanf("%d%d",&u,&v);
		a[u].push_back({v,w});
		a[v].push_back({u,w});
	}
	b[++tot]={1,0};
	while(tot!=0){
		bfs(b[1].to,b[1].w);
		swap(b[1],b[tot]);
		tot--;
		work1(1);
	}
	while(q){
		q--;
		int j,l;
		scanf("%d%d",&j,&l);
		if(l%2==0){
			if(l<ans[j][1]||(ans[j][1]==0&&j!=1)||ans[j][1]%2==1){
				printf("No\n");
			}
			else{
				printf("Yes\n");
			}
		}
		else if(l%2==1){
			if(l<ans[j][2]||ans[j][2]==0||ans[j][2]%2==0){
				printf("No\n");
			}
			else{
				printf("Yes\n");
			}
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}
2024/6/27 18:18
加载中...