跳到正文

个人记录

p5663

syzxcl约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年10月1日
收录
2026年10月1日
更新
2026年11月20日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+6;
vector<int>a[maxn];
bool bfs(int x,int l)
{
	queue<pair<int,int> >q;
	q.push(make_pair(x,l));
	while(!q.empty()){
		int x=q.front().first,l=q.front().second;
		if(x==1&&l==0)return true;
		if(l<0)break;
		q.pop();
		for(auto e:a[x])q.push(make_pair(e,l-1));
	}
	return false;
}
int main()
{
	int n,m,q;
	cin>>n>>m>>q;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	for(int i=1;i<=q;i++){
		int x,l;
		cin>>x>>l;
		bool flag=bfs(x,l);
		if(flag)cout<<"Yes"<<"\n";
		else cout<<"No"<<"\n";
}
}
原文