Go: package main

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

func main() {
	var n,m int
	fmt.Scan(&n)
	group := make([]int, n)
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = []int{}
		group[i] = -1
	}
	
	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())
		
		g[s] = append(g[s], t)
		g[t] = append(g[t], s)
	}
	for i := 0; i < n; i++ {
		if group[i] != -1 {
			continue
		}
		q := []int{i}
		for len(q) > 0 {
			pop := q[0]
			if len(q) > 1 {
				q = q[1:]
			} else {
				q = []int{}
			}
			if group[pop] == -1 {
				q = append(q, g[pop]...)
				group[pop] = i
			}
		}
	}
	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 group[s] == group[t] {
			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<stdio.h>
#include<queue>

#define MAX 100000

//int G[MAX+1][MAX+1];
int n, m;
std::queue<int> Q;

//bool bfs(int src, int dest) {
//    bool C[MAX];
//    for (int i = 0; i < n; ++i) C[i] = false;
//
//    Q.push(src);
//    while(!Q.empty()) {
//        int cur = Q.front();Q.pop();
//        for (int i = 0; i < n; ++i) {
//            if (G[cur][i] == 0) continue;
//            if (C[i]) continue;
//            if (i == dest) return true;
//            Q.push(i);
//            C[i] = true;
//        }
//    }
//
//    return false;
//}

int main() {
    //scanf("%d %d", &n, &m);
    //for (int i = 0; i < n; ++i) {
    //    for (int j = 0; j < n; ++j) {
    //        G[i][j] = 0;
    //    }
    //}
    //for (int i = 0; i < m; ++i) {
    //    int u,k;
    //    scanf("%d %d", &u, &k);
    //    G[u][k] = 1;
    //    G[k][u] = 1;
    //}

    //int q;
    //scanf("%d", &q);
    //for (int i = 1; i <= q; ++i) {
    //    int s,d;
    //    scanf("%d %d", &s, &d);
    //    bfs(s, d) ? printf("yes\n") : printf("no\n");
    //}

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

vector<vector<int>> A;
vector<int> color;
int num = 1;

void dfs(int u) {
    stack<int> S;
    S.push(u);
    color[u] = num;
    while (!S.empty()) {
        int now = S.top(); S.pop();
        rep(i, A[now].size()) {
            int next = A[now][i];
            if (color[next] == -1) {
                color[next] = num;
                S.push(next);
            }
        }
    }
    num += 1;
}

int main() {
    int n, m;
    cin >> n >> m;
    A = vector<vector<int>>(n);
    color = vector<int>(n, -1);
    rep(i, m) {
        int s, t;
        cin >> s >> t;
        A[s].push_back(t);
        A[t].push_back(s);
    }
    rep(i, n) {
        if (color[i] == -1) dfs(i);
    }
    int q;
    cin >> q;
    rep(i, q) {
        int s, t;
        cin >> s >> t;
        if (color[s] == color[t]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

C++: /**
 */

/*
 * test case 1
 2 1 1 2 1 1 2  
 test case 2
 4 4 1 2 1 3 2 4 3 4 1 1 2   
 */


#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector< vector<int> > rel;
vector<bool> visited;
int n, m, q;
int dest = 0;


bool fre1(int j) 
{
	for (int i=0;i<rel[j].size();i++)
	{
		int kk = rel[j][i];
		if (kk==dest) return true;
		if (visited[kk])continue;
		visited[kk]=true;
		if(fre1(kk))return true;
	}
	return false;
}

/**
 * preserve a priority que of nodes with the most connections. 
 * if there is a node with only 2 connections go look for the other one.
 */

priority_queue< pair<int, int> > pq;


bool fre3(int start) 
{
	for (int i=0;i<rel[start].size();i++)
	{
		int cand = rel[start][i];
		if (cand==dest) return true;
		if (visited[cand])continue;
		visited[cand]=true;
		int point = rel[cand].size();
		if (point == 1) continue;
		if (point == 2) {
			if (fre3(cand)) return true;
		} else {
			pq.push(pair<int, int>(point, cand));
		}
	}
	return false;
}


bool fre2(int start) 
{
	pq.push(pair<int,int>(0, start));
	while (pq.size())
	{
		pair<int, int> p = pq.top();
		pq.pop();
		start = p.second;
		if (fre3(start)) return true;
	}
	return false;
}


int main()
{
	cin >> n;
	rel.resize(n+1);
	cin >> m;
	for (int i=1;i<=m;i++){
		int j, k;
		cin >> j >> k;
		rel[j].push_back(k);
		rel[k].push_back(j);
	}

	cin >> q;
	for (int i=1;i<=q;i++){
		int start;
		cin >> start >> dest;
		visited.clear();
		visited.resize(n+1);
		cout << (fre2(start) ? "yes" : "no") << endl;
	}

	return 0;
}

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

vector<int> par(100005,-1);

void initialize(int n){
	for (int i=0;i<n;i++){
		par[i]=i;
	}
	return;
}

int root(int x){
	if (x==par[x]){
		return x;
	}else{
		return par[x]=root(par[x]);
	}
}

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

void uni(int x,int y){
	x=root(x);
	y=root(y);
	if(x==y){
		return;
	}else{
		par[x]=y;
	}
}

int main(){
	int n,m,q,i,j;
	int s,t;
	
	cin >> n >> m;
	
	initialize(n);
	
	for(i=0;i<m;i++){
		cin >> s >> t;
		uni(s,t);
	}
	
	cin >> q;
	
	for (i=0;i<q;i++){
		cin >> s >> t;
		if (find(s,t)){
			cout << "yes" <<endl;
		}else{
			cout << "no" <<endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//Union-Find??¨

int par[100000];//?±????????????£???
vector<vector<int> >v(100000);

int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);//????????§????????§???
}

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

void unify(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	par[x]=y;
}

int main(void){
	int n,m,f1,f2,q,s[10000],t[10000];
	cin>>n>>m;
	rep(i,n)par[i]=i;//union-find??¨????????????
	rep(i,m){
		cin>>f1>>f2;
		unify(f1,f2);
	}
	cin>>q;
	rep(i,q)cin>>s[i]>>t[i];//query
	rep(i,q)if(same(s[i],t[i])){
		cout<<"yes"<<endl;
	}else{
		cout<<"no"<<endl;
	}
	return 0;
}