You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
typedef pair<int, int> PII;
|
|
|
|
|
#define x first
|
|
|
|
|
#define y second
|
|
|
|
|
|
|
|
|
|
const int N = 1e5 + 10, M = N << 1;
|
|
|
|
|
|
|
|
|
|
// 20个测试点,过了7个,得了35分,其它TLE
|
|
|
|
|
// 邻接表
|
|
|
|
|
int e[M], h[N], idx, ne[M];
|
|
|
|
|
void add(int a, int b) {
|
|
|
|
|
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
|
|
|
|
|
}
|
|
|
|
|
bool bfs(int start, int dist) {
|
|
|
|
|
queue<PII> q;
|
|
|
|
|
q.push({start, dist});
|
|
|
|
|
|
|
|
|
|
while (q.size()) {
|
|
|
|
|
auto u = q.front();
|
|
|
|
|
q.pop();
|
|
|
|
|
|
|
|
|
|
if (u.x == 1 && u.y == 0) return true; // 在用完所有步数后,到达1号点,成功!
|
|
|
|
|
|
|
|
|
|
for (int i = h[u.x]; ~i; i = ne[i]) {
|
|
|
|
|
int v = e[i];
|
|
|
|
|
if (u.y) q.push({v, u.y - 1});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
// 链式前向星
|
|
|
|
|
memset(h, -1, sizeof h);
|
|
|
|
|
|
|
|
|
|
int n, m, Q;
|
|
|
|
|
cin >> n >> m >> Q;
|
|
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
|
int a, b;
|
|
|
|
|
cin >> a >> b;
|
|
|
|
|
add(a, b), add(b, a); // 无向图,双向建边
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (Q--) {
|
|
|
|
|
int u, dist;
|
|
|
|
|
cin >> u >> dist;
|
|
|
|
|
cout << (bfs(u, dist) ? "Yes" : "No") << endl;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|