Go: package main

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

const MAX = 100000

type Queue struct {
	head      int
	tail      int
	container [MAX]int
}

func (q *Queue) push(n int) {
	q.container[q.tail] = n
	q.tail = (q.tail + 1) % MAX
}

func (q *Queue) pop() int {
	res := q.container[q.head]
	q.head = (q.head + 1) % MAX
	return res
}

func (q *Queue) isEmpty() bool {
	return q.head == q.tail
}

var sc = bufio.NewScanner(os.Stdin)
var route [][]int
var SEEN [MAX]bool
var GROUP [MAX]int

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func bfs(start, group int) {
	que := Queue{}
	que.push(start)

	for !que.isEmpty() {
		id := que.pop()

		if SEEN[id] {
			continue
		}
		SEEN[id] = true
		GROUP[id] = group

		for _, next := range route[id] {
			que.push(next)
		}
	}
}

func main() {
	n, m := scanInt(), scanInt()
	route = make([][]int, n)
	for i := 0; i < m; i++ {
		s, t := scanInt(), scanInt()
		route[s] = append(route[s], t)
		route[t] = append(route[t], s)
	}

	for i := 0; i < n; i++ {
		if !SEEN[i] {
			bfs(i, i+1)
		}
	}

	w := bufio.NewWriter(os.Stdout)
	q := scanInt()
	for i := 0; i < q; i++ {
		s, t := scanInt(), scanInt()
		if GROUP[s] == GROUP[t] {
			fmt.Fprintln(w, "yes")
		} else {
			fmt.Fprintln(w, "no")
		}
	}
	w.Flush()
}

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

int fri[100010];

int find(int x){
  if( fri[x] == x ) return x;
  else return fri[x] = find(fri[x]);
}

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

void uf_union(int x, int y){
  x = find(x);
  y = find(y);
  fri[x] = y;
}

int main(){

  int n,m,q;
  cin >> n >> m;

  // init
  for(int i=0; i<n; i++) fri[i] = i;

  //
  for(int i=0; i<m; i++){
    int u,v; scanf("%d %d",&u,&v);
    uf_union(u,v);
  }

  cin >> q;
  for(int i=0; i<q; i++){
    int u,v; scanf("%d %d",&u,&v);
    if( find(u) == find(v) ) printf("yes\n");
    else printf("no\n");
  }


}

C++: #include <stdio.h>
#include <string.h>
#define N 100010
int father[N];
int findfather(int x){
    if(x == father[x]) return x;
    else return findfather(father[x]);
}
int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; i++) {
        father[i] = i;
    }
    for(int k = 0; k < m; k++){
        int a, b;
        scanf("%d %d", &a, &b);
        father[findfather(b)] = findfather(a);
    }

//    for(int i = 0; i < n; i++){
//        printf("i = %d father = %d\n", i, father[i]);
//    }
    int q;
    scanf("%d", &q);
    for(int k = 1; k <= q; k++){
        int x, y;
        scanf("%d %d", &x, &y);
        if(findfather(x) == findfather(y)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

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

using namespace std;

const int MAX = 100000;

vector<int> G[MAX];
int C[MAX] = {0};

void dfs(int u, int c) {
    if (C[u] == 0) {
        C[u] = c;
        for (auto v : G[u]) {
            if (C[v] == 0) dfs(v, c);
        }
    }
}

int main() {

    int n, m;
    cin >> n >> m;

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

    int c = 1;
    for (int i = 0; i < n; i++) {
        if (C[i] == 0) dfs(i, c++);
    }

    //
    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        if (C[s] != 0 && C[s] == C[t]) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int n, m;
struct node {
    int id;
    node* parent;
};

node find(node x){
    if(x.parent == NULL)
        return x;
    else
        x = find(*x.parent);
    return x;
}

void marge(node x, node y){
    x = find(x);
    y = find(y);
    if(x.id == y.id)
        return;
    else
        y.parent = &x;
    return;
}

bool judge(node x, node y){
    x = find(x);
    y = find(y);
    return x.id == y.id;
}

int main() {
    cin >> n >> m;
    node person[n];
    REP(i, n){
        person[i].id = i;
        person[i].parent = NULL;
    }
    REP(i, m){
        int s, t;
        cin >> s >> t;
        if(person[t].parent == NULL)
            person[t].parent = &person[s];
        else if(person[s].parent == NULL)
            person[s].parent = &person[t];
        else marge(person[s], person[t]);
    }
    int q;
    cin >> q;
    REP(i, q){
        int s, t;
        cin >> s >> t;
        if(judge(person[s], person[t]))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<queue>

#define MAX 1000

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++: //#define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX 100
#define _MAX 1000
struct Graph
{
	int id, k = 0;
	list<int> node;
	int d = -1;
};
Graph G[MAX];
list<int> co;
int bo = false;
void Connect(Graph *g,Graph *f)
{
	if (g->k >= 0) {
		int a = true;
		co.push_back(g -> id);
		printf("%d,", g->id);
		for (auto i = g->node.begin(); i != g->node.end(); ++i) {
			if (&G[*i] == f) { bo = true; return; }
			for (auto j = co.begin(); j != co.end(); ++j) {
				if (*j == *i) {
					a = false;
					break;
				}
			}
			if(a) return Connect(&G[*i], f);
			a = true;
		}
	}
}
int main(void)
{
	int n, m, q, a, b;
	int qq[_MAX] = { 0 };
	scanf_s("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf_s("%d %d", &a, &b);
		G[a].id = a; G[b].id = b;
		++G[a].k; G[a].node.push_back(b);
		++G[b].k; G[b].node.push_back(a);
	}
	scanf_s("%d", &q);
	for (int i = 0; i < q; ++i) {
		scanf_s("%d %d", &a, &b);
		bo = 0;
		Connect(&G[a], &G[b]);
		qq[i] = bo;
		co.clear();
	}
	for (int i = 0; i < q; ++i) {
		if(qq[i]) printf("yes\n");
		else printf("no\n");
	}
}