This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#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;
}