自测对了,交错了,求助
查看原帖
自测对了,交错了,求助
466909
Lijinghao168楼主2023/8/7 11:59
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,t;
int ji[N],ou[N];
vector<int>v[N];
void bfs(){
	memset(ji,0x3f3f3f3f,sizeof(ji));
	memset(ou,0x3f3f3f3f,sizeof(ou));
	queue<int>q;
	ou[1]=0;
	q.push(1);
	q.push(0);
	while(q.size()){
		int x=q.front();
		q.pop();
		int f=q.front();
		q.pop();
		for(auto k : v[x]){
			if(f%2==1){
				if(f+1<ou[k]){
					ou[k]=f+1;
					q.push(k);
					q.push(f+1);
				}
			}else{
				if(f+1<ji[k]){
					ji[k]=f+1;
					q.push(k);
					q.push(f+1);
				}
			}
		}
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>t;
	for(int i=1;i<=m;i++){
		int u,w;
		cin>>u>>w;
		v[u].push_back(w);
		v[w].push_back(u);
	}
	bfs();
	while(t--){
		int x,y;
		cin>>x>>y;
		if(y%2==0){
			if(ou[x]>y)cout<<"NO";
			else cout<<"YES";
		}else{
			if(ji[x]>y)cout<<"NO";
			else cout<<"YES";
		}
		cout<<'\n';
	}
	return 0;
}

https://www.luogu.com.cn/paste/ek7bpl9x

点一 答案是 No Yes No 咋了?

2023/8/7 11:59
加载中...