-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patha.cpp
More file actions
59 lines (56 loc) · 1001 Bytes
/
a.cpp
File metadata and controls
59 lines (56 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool bfspath(vector<vector<ll>> adj,ll n,ll s,ll d)
{
if(s==d)
{
return true;
}
vector<bool> visited(n,false);
queue<ll> q;
q.push(s);
visited[s]=true;
while(!q.empty())
{
ll current=q.front();
q.pop();
for(auto i:adj[current])
{
if(i==d)
{
return true;
}
if(!visited[i])
{
q.push(i);
visited[i]=true;
}
}
}
return false;
}
int main()
{
ll n,e;
cin>>n>>e;
vector<vector<ll>> adj;
ll u,v;
for(ll i=0;i<e;++i)
{
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
ll q;
cin>>q;
int s,d;
while(q--)
{
cin>>s>>d;
if(bfspath(adj,n,s,d))
cout<<"yes"<<endl;
else
cout<< "no"<<endl;
}
}