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 <vector>

using namespace std;

#define N_MAX 100000

int search_connection(int s, int t);
vector<int> G[N_MAX], check_v;

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

    cin >> n >> m;

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

    //??????????????????
    cin >> q;
    for (i = 0; i < q; i++) {
//        cout << "Q. " << i << endl;

        cin >> s >> t;

        if (check_v.size() != 0) check_v.clear();

        check_v.push_back(s);
        if ( search_connection(s, t) )
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}

int search_connection(int s, int t) {
    int i;
//    cout << "search " << s << ", " << t << endl;

    for (auto itr = G[s].begin(); itr != G[s].end(); itr++) {
        if (*itr == t) {
            return 1;
        }
        else if ( find(check_v.begin(), check_v.end(), *itr) != check_v.end() ) {
            //*itr?????¢?????¢?´¢??????node?????´??????????????¢?´¢????????????
        }
        else {
            //*itr???????????¢?´¢???????????????node?????´???
            check_v.push_back(*itr);
            if ( search_connection(*itr, t) )
                return 1;
        }
    }

    return 0;
}

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

int main(){
  int n,m,q,a,b,s,t,k,h;
  vector<int> g[100001];
  queue<int> qu;
  set<int> ch;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>s>>t;
    
    k=0; 
    ch.clear();
    while(qu.size()){
      qu.pop();
    }
    qu.push(s);
    
    while(qu.size()){//?????????
      n=qu.front();qu.pop();
      
      for(int j=0;j<g[n].size();j++){//????????????????????´????????????
	if(g[n][j]==t){
	  cout<<"yes"<<endl;
	  k++;
	  break;
	}
	if(ch.count(g[n][j])==0 ){
	  qu.push(g[n][j]);
	  ch.insert(g[n][j]);
	}
      }
      if(k>=1)break;
    }
    
    if(k==0)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 i=0;i<n;i++){
        if(color[i]==NIL)
            dfs(i,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"<<"\n";
        else cout<<"no"<<"\n";
    }
    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 <stdio.h>
#include <stack>
#include <iostream>
using namespace std;
int G[10000][10000];
int vis[100000];
int n;

bool dfs(int s, int t)
{
    if (G[s][t] == 1 || G[t][s] == 1) return true;
    vis[s] = 1;
    for (int i = 0; i < n; i++)
    {
        if (G[s][i] == 1 && vis[i] == 0)
            {
                bool a = (dfs(i,t)); 
                if(a) 
                {
                    vis[s] = 0;
                    return a;
                }
            }

    } 
    vis[s] = 0;
    return false;
}

int main()
{
    //freopen("in3.txt","r",stdin);
    int m;
    scanf("%d %d",&n, &m);
    for (int i = 0; i < n; i++)
    {
        vis[i] = 0; 
    } 
    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 s, t;
        scanf("%d %d",&s,&t); 
        G[s][t] = 1;
        G[t][s] = 1;
    } 
    int q,s,t;
    scanf("%d",&q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d",&s,&t);
        if(dfs(s,t)||dfs(t,s)) printf("yes\n");
        else printf("no\n");
    } 
    return 0;
}

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

using namespace std;

const int MAX = 100000;

int parent(int table[], int child) {

	while (table[child] != -1) {
		q.push(child);
		child = table[child];
	}
	return child;
}

int main() {
	int n, m, q;
	int table[MAX];

	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; i++)table[i] = -1;
	for (int i = 0; i < m; i++) {
		int s, t;
		scanf("%d %d", &s, &t);
		
		int ps = parent(table, s);
		int pt = parent(table, t);
		if (ps != pt) {
			table[ps] = pt;
		}
	}

	scanf("%d", &q);

	for (int i = 0; i < q; i++) {
		int s, t;
		
		scanf("%d %d", &s, &t);

		int ps = parent(table, s);
		int pt = parent(table, t);

		if (ps == pt) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}
	return 0;
}