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++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)

vector<int> adjacencyList[100005];//??£??\?????????

int n;
int color[100005];//????????????????????°?????????????±???????????????????


void assignColor() {
	REP(i, n) color[i] = -1; //?????????

	//?????????
	color[0] = 0;
	int next_index;
	REP(i, n) {
		if (color[i] == -1) color[i] = i;//????????????????????????i??§??????
		//???????????????????????????????????????????????\?????????????????????

		for (int j = 0;j < adjacencyList[i].size();j++) {
			next_index = adjacencyList[i][j]; //??£??\????????????????¬?????????????????????????
			if (color[next_index] == -1) {//??????????????????????????????i????????§??????
				color[next_index] = color[i];
			}
		}
	}
}

bool IsConCom(int s, int t) {
	//s,t???????????°?????????(???)?????????
	return color[s] == color[t];
}

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

	int s, t;
	REP(i, m) {
		cin >> s >> t;
		adjacencyList[s].push_back(t);
		adjacencyList[t].push_back(s);
	}

	assignColor();//?????????

	int q;
	cin >> q;
	REP(i, q) {
		cin >> s >> t;//s??????t?????????????????¨???????????¨???

		(IsConCom(s, t)) ? cout << "yes" : cout << "no";
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
 
int main() {
int d[100100];
int m,n,q;
scanf("%d %d", &n,&m);
for(int i=0;i<n;i++){
    d[i]=i;
}
for(int l=0;l<m;l++){
    int a,b;
    cin>>a>>b;
    int j ,h;
    j=a,h=b;
while(d[j]!=j ||d[h]!=h){
    j=d[j];
    h=d[h];
}
d[j]=h;
while(a!=h ||b!=h){
 
    d[a]=h;
    d[b]=h;
a=d[a];
b=d[b];
}
}

scanf("%d",&q);
for(int y=0;y<q;y++){
    int a,b;
scanf("%d %d", &a,&b); 
        int j ,h;
    j=a,h=b;
while(d[j]!=j ||d[h]!=h){
    j=d[j];
    h=d[h];
}
    if(j==h){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
}
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;


int n;
vector<int> G[MAX];
int color[MAX];

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 s, t, m, q;

	cin >> n >> m;

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

	assignColor();

	cin >> q;

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

	return 0;
}

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

using namespace std;

int p[100010];

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

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

void unit(int a,int b)
{
    int fa=fnd(a),fb=fnd(b);

    if(fa!=fb)
    {
        p[fa]=fb;
    }
}

bool same(int a,int b)
{
    return fnd(a)==fnd(b);
}

int main()
{

    int n,m,q;

    cin>>n>>m;

    init(n);

    int a,b;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        unit(a,b);
    }

    cin>>q;

    for(int i=0;i<q;i++)
    {
        cin>>a>>b;

        if(same(a,b))
        {
            cout<<"yes"<<endl;
        }else
        {
            cout<<"no"<<endl;
        }
    }





    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
static const int MAX=100000;
using namespace std;

vector<int> follow[MAX];
int color[MAX];  //-1 represent No Visited

void bfs(int i,int c)
{
    queue<int> Q;
    Q.push(i);color[i]=c;
    while(!Q.empty())
    {
        int p=Q.front();Q.pop();
        for(int j=0;j<follow[p].size();j++)
        {
            if(color[follow[p][j]]!=-1) continue;
            //else
            Q.push(follow[p][j]); color[follow[p][j]]=color[p];
        }
    }
}

int main()
{
   int n,m;
   cin>>n>>m;
   for(int i=0;i<n;i++) color[i]=-1;
   for(int i=0;i<m;i++)
   {
       int a,b;
       cin>>a>>b;
       follow[a].push_back(b);
       follow[b].push_back(a);
   }
   int c=0;
   for(int i=0;i<n;i++)
   {
       if(color[i]==-1)
       {
           bfs(i, c);
           c++;
       }
   }
   int order_num;cin>>order_num;
   for(int i=0;i< order_num;i++)
   {
       int a,b;
       cin>>a>>b;
       if(color[a]==color[b]) cout<<"yes"<<endl;
       else cout<<"no"<<endl;
   }
}

C++: #include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX=100000;
static const int NIL=-1;

int n;
vector<int> g[MAX];
int color[MAX];

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++){
    int v=g[u][i];
    if(color[v]==NIL) dfs(u,id++);
  }
}

int main(){
  int s,t,m,q;

  cin>>n>>m;

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

  assignColor();

  cin>>q;

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