1164加工零件
作者:
jy9
,
2024-08-17 15:14:04
,
所有人可见
,
阅读 1
有问题尚未解决
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int N = 1e6+10;
const int M = 2e6+10;
int n, m, q;
int dist[N][2];
bool st[N][2];
struct node{
int v, st;
};
vector<int> h[N];
void bfs(){
queue<node> q;
q.push({1, 0});
dist[1][0] = 0;
st[1][0] = 1;
while(q.size()){
auto [t, step] = q.front();
q.pop();
// if(st[t][step])continue; 不能加这句代码,原因未知
st[t][step] = 1; //这句代码似乎不必要出现
for(auto u:h[t]){
if(st[u][!step]) continue;
dist[u][!step] = dist[t][step] + 1;
st[u][!step] = 1;
q.push({u, !step});
}
}
}
int main(){
memset(dist, 0x3f, sizeof dist);
cin >> n >> m >> q;
int a, b;
for (int i = 1; i <= m; i ++ ){
cin >> a >> b;
h[a].push_back(b);
h[b].push_back(a);
}
bfs();
int A, L;
for (int i = 1; i <= q; i ++ ){
cin >> A >> L;
if(h[1].empty()) cout << "No" << endl;
else if(dist[A][L&1] <= L)cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}