35分 本蒟蒻不会优化,帮帮忙
查看原帖
35分 本蒟蒻不会优化,帮帮忙
775490
JMCJimmyMaker楼主2023/6/17 16:21
//define and head file
#include <bits/stdc++.h>     //万能头文件
using namespace std;
//variables and structions
int n, m, q;
vector<int> vec[100005];
//functions

//main function(run)
int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < m; i++)
	{
		int x, y; cin >> x >> y;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	for (int i = 0; i < q; i++)
	{
		queue<int> que;
		int px, py;
		cin >> px >> py;
		for (int k = 0; k < vec[px].size(); k++)
		{
			que.push(vec[px][k]);
		}
		int len = vec[px].size();
		for (int j = 0; j < py - 1; j++)
		{
			while (len > 0)
			{
				int x = que.front();
				que.pop();
				for (int k = 0; k < vec[x].size(); k++)
				{
					que.push(vec[x][k]);
				}
				len--;
			}
			len = que.size();
		}
		bool t = 0;
		while (!que.empty())
		{
			int x = que.front();
			if (x == 1)
			{
				t = 1; break;
			}
			que.pop();
		}
		if (t) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

35分

2023/6/17 16:21
加载中...