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 <bits/stdc++.h>
using namespace std;
vector<int> G[100000];
int group[100000]={0};

void dfs(int v,int g){
	group[v] = g;
	for(int i=0;i<G[v].size();i++)
		if(!group[G[v][i]]) 
			dfs(G[v][i],g);
}

int main()
{	
	int n,m,u,v;
	cin>>n>>m;
	while(m--){
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int g = 1;
	for(int i=0;i<n;i++)
		if(!group[i]) dfs(i,g++);
	cin>>m;
	while(m--){
		scanf("%d%d",&u,&v);
		if(group[u]==group[v])
			puts("yes");
		else puts("no");
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int Max = 100000;
static const int NIL = -1;
int i, j, v, num, color[Max];
vector<int> list[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(i=0; i<list[u].size(); i++){
     v = list[u][i];
     if(color[v] == NIL){
       color[v] = c;
       S.push(v);
     }
   }
 }
}
  
void assigncolor(){
 int id = 1;
 for(i=0; i<num; i++){
   color[i] = NIL;
 }
 for(j=0; j<num; j++){
   if(color[j] == NIL)
     dfs(i, id++);
 }
}
  
int main(){
 int a, b, trial, start, goal, kaisuu;
 cin >> num >> kaisuu;
  
 for(i=0; i<kaisuu; i++){
   cin >> a >> b;
   list[a].push_back(b);
   list[b].push_back(a);
 }
 
 assigncolor();
 
 cin >> trial;
 
 for(i=1; i<=trial; i++){
   cin >> start >> goal;
   if(color[start] == color[goal]){  
     cout << "yes" << endl;
   } else{
     cout << "no" << endl;
   }
 }
  
 return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;
const int maxx = 100010;
int n, m;
int u, num, v;
int flag[maxx];
int color[maxx];
vector<int> G[maxx];

int c = 1;
void dfs(int t) {
	stack<int>s;
	s.push(t);
	color[t] = c;
	while (!s.empty()) {
		int u = s.top(); s.pop();
		int len = G[u].size();
		for (int i = 0; i < len; i++) {
			int v = G[u][i];
			if (flag[v] == 0) {
				color[v] = c;
				flag[v] = 1;
				s.push(v);
			}
		}
	}
}
int main()
{
	int q;
	memset(flag, 0, sizeof(flag));
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &u, &v);
		//?°???¶???v????????°G[u]??°??????
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for (int i = 0; i < n; i++) {
		if (flag[i] == 0) {
			dfs(i);
			c++;
		}
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d %d", &u, &v);
		if (color[u] == color[v]) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include<stack>
using namespace std;
static const int MAX = 10000;
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 assign(){
	int id=1;
	for(int i=0;i<n;i++){
		color[i] = NIL;
	}
	for(int j=0;j<n;j++){
		if(color[j]==NIL){
			dfs(j,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);
	}
	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 <algorithm>
#include <iostream>
#include <string>
#include <vector>

class TUser
{
	std::vector<TUser*> FAccessible;
public:
	void AddFriend(TUser* Friend);
	bool IsAccesible(const TUser* Target)const;
};

void TUser::AddFriend(TUser* Friend)
{
	if(IsAccesible(Friend)) return;
	FAccessible.push_back(Friend);
	for(unsigned int i = 0; i < FAccessible.size(); ++i){
		FAccessible[i]->AddFriend(Friend);
	}
}

bool TUser::IsAccesible(const TUser* Target)const
{
	return std::find(FAccessible.begin(), FAccessible.end(), Target) != FAccessible.end();
}

class TSns
{
	std::vector<TUser> FUsers;
public:
	TSns(int UserCount);
	
	void AddLink(int UserA, int UserB);
	std::string IsAccesible(int UserA, int UserB)const;
};

TSns::TSns(int UserCount)
: FUsers(UserCount)
{
}

void TSns::AddLink(int UserA, int UserB)
{
	FUsers[UserA].AddFriend(&FUsers[UserB]);
	FUsers[UserB].AddFriend(&FUsers[UserA]);
}

std::string TSns::IsAccesible(int UserA, int UserB)const
{
	if(FUsers[UserA].IsAccesible(&FUsers[UserB]) || FUsers[UserB].IsAccesible(&FUsers[UserA])) return "yes";
	return "no";
}

int main()
{
	int UserCount;
	std::cin >> UserCount;
	TSns Sns(UserCount);
	
	int LinkCount;
	std::cin >> LinkCount;
	for(int i = 0; i < LinkCount; ++i){
		int UserA, UserB;
		std::cin >> UserA >> UserB;
		Sns.AddLink(UserA, UserB);
	}
	
	int QuestionCount;
	std::cin >> QuestionCount;
	for(int i = 0; i < QuestionCount; ++i){
		int UserA, UserB;
		std::cin >> UserA >> UserB;
		std::cout << Sns.IsAccesible(UserA, UserB) << std::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(s);
  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 m, s, t;

  cin >> n >> m;

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

  assignColor();

  int q;
  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;
}