Go: package main

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

func main() {
	var n,m int
	fmt.Scan(&n)
	group := make([]int, n)
	for i := 0; i < n; i++ {
		group[i] = i
	}
	
	fmt.Scan(&m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < m; i++ {
		sc.Scan()
		s, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())

		if group[s] < group[t] {
			group[t] = group[s]
		} else {
			group[s] = group[t]
		}
	}

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	for i := 0; i < q; i++ {
		sc.Scan()
		s, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())

		if root(s, &group) == root(t, &group) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

func root(i int, group *[]int) int {
	if i == (*group)[i] {
		return i
	}
	(*group)[i] = root((*group)[i], group)
	return (*group)[i]
}

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

vector<vector<int> > G;
vector<int> is_visited;
int b;

bool DFS(int a, int i) {
    if (a == b) return true;
    if (i >= G[a].size()) return false;
    is_visited[a] = 1;
    if (!is_visited[G[a][i]] && DFS(G[a][i], 0)) {
        return true;
    }
    return DFS(a, i + 1);
}

// bool DFS(const vector<vector<int> >& G,
//          vector<bool>& is_visited, int a, int b, int i) {
//     if (a == b) return true;
//     if (i >= G[a].size()) return false;
//     is_visited[a] = true;
//     if (!is_visited[G[a][i]] && DFS(G, is_visited, G[a][i], b, 0)) {
//         return true;
//     }
//     return DFS(G, is_visited, a, b, i + 1);
// }

int main(){
    int n, m;
    cin >> n >> m;

    G.resize(n);
    is_visited.resize(n);

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

// for (int i = 0; i < n; i++) {
//     cout << i << " : ";
//     for (int j = 0; j < G[i].size(); j++){
//         cout << G[i][j] << " ";
//     }
//     cout << endl;
// }



    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a;
        cin >> a >> b;
        for (int j = 0; j < n; j++) {
            is_visited[j] = 0;
        }
        if (DFS(a, 0)) {
            cout << "yes" << endl;
        } else {
            cout << "no"  << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
#define MAX 101000

int ran[MAX], par[MAX];

int init(int n){
	for(int i = 0; i < n; i++){
		ran[i] = 0;
		par[i] = i;
	}
}

int find(int x){
	return par[x] ==  x ? x : par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	
	if(x == y)return;
	
	if(ran[y] > ran[x]){
		par[x] = y;
	} else {
		par[y] = x;
		if(ran[y] == ran[x]) ran[x]++;
	}
}

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


int main(){
	int n, m, q, s, t;
	
	cin>>n>>m;
	
	init(n);
	
	for(int i = 0; i < m; i++){
		cin>>s>>t;
		unite(s,t);
	}
	
	cin>>q;
	
	for(int i = 0; i < q; i++){
		cin>>s>>t;
		cout<<(same(s,t)?"yes":"no")<<endl;
	}
	
	
	return 0;
}