全re(玄关)
查看原帖
全re(玄关)
1199534
ycy1124楼主2024/6/27 16:35
#include<bits/stdc++.h>
using namespace std;
int 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%d",&u,&v);
		a[u].push_back({v,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){
		int j,l;
		scanf("%d%d",&j,&l);
		if((ans[j][1]<l&&ans[j][1]!=0)||(ans[j][2]<l&&ans[j][2]!=0)){
			printf("No\n");
		}
		else{
			printf("Yes\n");
		}
	}
	return 0;
}
2024/6/27 16:35
加载中...