Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Code
SUBMITTED BY:
FRmaxFR
DATE:
Feb. 16, 2019, 12:56 p.m.
FORMAT:
Text only
SIZE:
693 Bytes
Raw
Download
Tweet
HITS:
1336
Go to comments
Report
#include<bits/stdc++.h>
using namespace std;
vector<int> G[1000000];
int check[1000000];
int comp;
void dfs(int u){
check[u]=comp;
for(auto v:G[u]){
if(!check[v]) dfs(v);
}
return ;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int x,y;
while(m--){
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
}
for(int i=1;i<=n;i++){
if(!check[i]){
comp++;
dfs(i);
}
}
int q;
scanf("%d",&q);
while(q--){
scanf("%d%d",&x,&y);
if(check[x]==check[y]) printf("Yes\n");
else printf("No\n");
}
return 0;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus