0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P5663 [CSP-J2019] 加工零件

R54732144
This commit is contained in:
Baoshuo Ren 2021-08-01 21:39:24 +08:00 committed by Baoshuo Ren
parent b6ee5f6b23
commit 3f22ebe950
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, q, u, v, a, l, dist[100005][2];
vector<pair<int, int>> g[100005];
bool flag;
void bfs() {
memset(dist, 0x3f, sizeof(dist));
dist[1][0] = 0;
queue<pair<int, int>> q;
q.push(make_pair(1, 0));
while (!q.empty()) {
auto t = q.front();
q.pop();
for (auto i : g[t.first]) {
if (dist[i.first][t.second ^ 1] == 0x3f3f3f3f) {
dist[i.first][t.second ^ 1] = dist[t.first][t.second] + 1;
q.push(make_pair(i.first, t.second ^ 1));
}
}
}
}
int main() {
cin >> n >> m >> q;
for (int i = 1; i <= m; i++) {
cin >> u >> v;
g[u].push_back(make_pair(v, 1));
g[v].push_back(make_pair(u, 1));
flag = flag || u == 1 || v == 1;
}
bfs();
for (int i = 1; i <= q; i++) {
cin >> a >> l;
cout << (flag && l >= dist[a][l & 1] ? "Yes" : "No") << endl;
}
return 0;
}