Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	nodes := make([]Node, n)

	for i := 0; i < n; i++ {
		nodes[i].list = make([]int, 0)
	}

	for i := 0; i < m; i++ {
		s := getNextInt(scanner)
		t := getNextInt(scanner)
		nodes[s].list = append(nodes[s].list, t)
		nodes[t].list = append(nodes[t].list, s)
	}

	c := 1
	for i := 0; i < n; i++ {
		if nodes[i].c == 0 {
			traverse(nodes, i, c)
			c++
		}
	}

	q := getNextInt(scanner)

	for i := 0; i < q; i++ {
		s := getNextInt(scanner)
		t := getNextInt(scanner)
		if nodes[s].c == nodes[t].c {
			fmt.Fprintln(writer, "yes")
			continue
		}
		fmt.Fprintln(writer, "no")
	}

	writer.Flush()
}

// Node ...
type Node struct {
	list []int
	c    int
}

func traverse(nodes []Node, r, c int) {
	nodes[r].c = c
	for _, i := range nodes[r].list {
		if nodes[i].c != 0 {
			continue
		}
		traverse(nodes, i, c)
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>

#define N 100005
#define UNDEFINED -1

int n, m, s, t, q;
std::vector<int> adj[N];
int group[N];

void dfs(int x, int g) {
    std::stack<int> S;
    S.push(x);
    group[x] = g;
    while(!S.empty()) {
        int u = S.top(); S.pop();
        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i];
            if(group[v] == UNDEFINED) {
                group[v] = g;
                S.push(v);
            }
        }
    }
}

int main() {
    for(int i = 0; i < N; i++) {
        group[i] = UNDEFINED;
    }

    std::cin >> n >> m;
    for(int i = 0; i < m; i++) {
        std::cin >> s >> t;
        adj[s].push_back(t);
        adj[t].push_back(s);
    }

    int g = 0;
    for(int i = 0; i < n; i++) {
        if(group[i] == UNDEFINED) {
            dfs(i, g++);
        }
    }


    std::cin >> q;
    for(int i = 0; i < q; i++) {
        std::cin >> s >> t;
        if(group[s] != UNDEFINED && group[t] != UNDEFINED && group[s] == group[t]) {
            puts("yes");
        } else {
            puts("no");
        }
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_p
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

#define N 100000
int r[N],p[N];

void init(int n){
    int i;
    rep(i,n){
        p[i]=i;
        r[i]=0;
    }
}

int find_set(int x){
    if(x!=p[x])
        p[x]=find_set(p[x]);
    return p[x];
}

void link(int x,int y){
    if(r[x]>r[y])
        p[y]=x;
    else{
        p[x]=y;
        if(r[x]==r[y])
            r[y]++;
    }
}
void unite(int x,int y){
    link(find_set(x),find_set(y));
}

int same(int x,int y){
    return find_set(x)==find_set(y);
}

void run(){
    int n,m;
    cin>>n>>m;
    init(n);
    int s,t;
    rep(i,m){
        cin>>s>>t;
        unite(s,t);
    }
    int q;
    cin>>q;
    rep(i,q){
        cin>>s>>t;
        yes(same(s,t));
    }
}

C++: #include <iostream>
#include <vector>
using namespace std;

bool search(vector<int> member,int x){
  for(int i=0; i<member.size(); i++){
    if(member[i] == x)
      return true;
  }
    return false;
}
vector<int> update(vector<int> mother,vector<int> children,int join[],int a,int b){
  mother.push_back(b);
  join[b] = join[a];
  for(int i=0; i<children.size(); i++){
    int num=children[i];
    mother.push_back(num);
    join[num] = join[a];
  }

  return mother;
}
int main(){
  int n,m,join[10000],s,t;
  vector<int> group[10000];
  cin >> n >> m;

  for(int i=0; i<n; i++)
    join[i] = i;
    
  for(int i=0; i<m; i++){
    cin >> s >> t;
    bool flag = search(group[join[t]],s);

    if(!flag){
      int x = join[t];

      if(x!=t || !group[x].empty())
	group[x] = update(group[x],group[s],join,x,s);


      else{
	group[join[s]].push_back(t);
	join[x] = join[s];
      }
    }

  }
 
  int q;
  cin >> q;
  
  bool answer[10000];
  for(int i=0; i<q; i++){
    cin >> s >> t;
    
    if(join[s] == join[t])
      answer[i]=true;
    else
      answer[i]=false;
  }

  for(int i=0; i<q; i++){
    if(answer[i])
      cout << "yes\n";
    else
      cout << "no\n";
  }
}

C++: #include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define NIL -1
int n,m;
int color[1000100];
vector<int>G[100100];

void dfs(int r, int c){
  stack<int> S;
  S.push(r);
  color[r]=c;
  while(!S.empty()){
    int u=S.top();S.pop();
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      if(color[v]==NIL){
        color[v]=c;
        S.push(v);
      }
    }
  }
}

void assignColor(){
  int id=1;
  for(int i=0;i<n;i++)color[i]=NIL;
  for(int u=0;u<n;u++){
    if(color[u]==NIL)dfs(u,id++);
  }
}

int main(){
  int t,s,p,q,k,l;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>t>>s;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin>>p;
  for(int i=0;i<p;i++){
    cin>>k>>l;
    if(color[k]==color[l]){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
  }
}

C++: #include <iostream>

using namespace std;

const int N = 100000;
int A[N][N] = {{0}};
int n;

bool dfs(int s, int t) {
    if (A[s][t] == 1) {
        return true;
    }
    for (int i = 0; i < n; ++i) {
        if (i != t && A[s][i] != 0) {
            if (dfs(i, t)) {
                return true;
            }
        }
    }
    return false;
}

int main() {
    int m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int s, t;
        cin >> s >> t;
        A[s][t] = 1;
    }

    int q;
    cin >> q;
    for (int j = 0; j < q; ++j) {
        int x, y;
        cin >> x >> y;

        if (dfs(x, y)) {
            cout << "yes";
        } else {
            cout << "no";
        }
        cout << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
stack<int> S;

void boo(int b[], int y[], int w, int m){
	for(int i = 0; i < m; i++){
		if(b[i] == w) {
			if(y[b[i + m]] != -1){
				S.push(b[i + m]);
				y[b[i + m]] = 1;
			}
		}
	}
	for(int i = m; i < m * 2; i++){
		if(b[i] == w) {
			if(y[b[i - m]] != -1){
				S.push(b[i - m]);
				y[b[i - m]] = 1;
			}
		}
	}
}

int foo(int a, int s, int b[], int m, int n){
	int y[100100] = {}, i;

	
	S.push(a);
	y[a] = 1;
	
	while(S.empty() != true){
		i = S.top(); S.pop(); 
		if(i == s){
			return true;
		} else{
			y[i] = -1;
			boo(b, y, i, m);
		}
	}
	
	return false;
}

int main(){
	int b[200100];
	int n, m, q, a, s;
	int i, j, k;
	cin>>n>>m;
	for(i = 0; i < m; i++){
		cin>>b[i]>>b[m + i];
	}

	cin>>q;

	for(i = 0; i < q; i++){
		cin>>a>>s;
		if(foo(a, s, b, m, n) == 1){
			cout<<"yes"<<endl;
		} else {
			cout<<"no"<<endl;
		}
	}
	
	return 0;
}