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 <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

int n, m;
vector<vector<int>> g;
int color[100000];

void dfs(int s, int col) {
	if (color[s] > 0)
		return;
	color[s] = col;

	for (int i = 0; i < g[s].size(); ++i) {
		dfs(g[s][i], col);
	}
}

int main() {
	int q, s, t;
	cin >> n >> m;
	g.resize(n);
	while (m--) {
		cin >> s >> t;
		g[s].push_back(t);
		g[t].push_back(s);
	}

	int col = 1;
	for (int i = 0; i < n; ++i) {
		dfs(i, col++);
	}

	cin >> q;
	while (q--) {
		cin >> s >> t;
		if (color[s] == color[t])
			yes();
		else
			no();
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

class UnionFind {
public:
    vector<int> par;
    int num;

    UnionFind(int n) : par(n, -1), num(n) {};

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

    int size(int x) {
        return -par[root(x)];
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        num--;
        return true;
    }

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

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        if (!uf.same(x, y)) uf.unite(x, y);
    }
    int q;
    cin >> q;
    vector<string> ans(q);
    rep(i, 0, q) {
        int x, y;
        cin >> x >> y;
        if (uf.same(x, y)) ans[i] = "yes";
        else ans[i] = "no";
    }

    rep(i, 0, q) cout << ans[i] << endl;
    return 0;
}

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

int x[100000][1000];
bool y[100000];
int z[100000];

int main(){
	int n,m,a,b,q;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		x[a][z[a]]=b;
		x[b][z[b]]=a;
		z[a]++;
		z[b]++;
	}
	cin>>q;
	for(int h=0;h<q;h++){
		cin>>a>>b;
		memset(y,0,sizeof(y));
		y[a]=true;
		for(int i=0;i<50;i++){
			for(int j=0;j<n;j++){
				if(y[j]==true){
					for(int k=0;k<z[j];k++){
						y[x[j][k]]=true;
					}
				}
				if(y[b]==true){
					cout<<"yes"<<endl;
					goto Exit;
				}
			}
		}
		cout<<"no"<<endl;
		Exit:;
	}
	return 0;
}

C++: /* 
 * ALDS1_11B.cpp
 */
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

using Friends = vector<int>;
using SNS = vector<Friends>;

int n, m, q;
bool visited[100000];
SNS sns;

SNS allfriend;

bool is_friend(int id, int target) {
    if (visited[id])
        return false;

    visited[id] = true;
    for (int i = 0; i < sns[id].size(); ++i) {
        int now = sns[id][i];
        if (now == target)
            return true;
        if (is_friend(now, target))
            return true;
    }
    return false;
}

void makefriendlist(int id, int now) {
    if (visited[now])
        return;

    visited[now] = true;
    allfriend[id].push_back(now);
    for (int i = 0; i < sns[now].size(); ++i) {
        makefriendlist(id, sns[now][i]);
    }
}

bool isfriend(int id, int target) {
    for (int i = 0; i < allfriend[id].size(); ++i)
        if (allfriend[id][i] == target)
            return true;
    for (int i = 0; i < allfriend[target].size(); ++i)
        if (allfriend[target][i] == id)
            return true;
    return false;
}

int main(void) {

    scanf("%d %d", &n, &m);
    sns.resize(n);
    allfriend.resize(n);
    for (int i = 0, id, f; i < m; ++i) {
        scanf("%d %d", &id, &f);
        sns[id].push_back(f);
        sns[f].push_back(id);
    }

    for (int i = 0; i < n; ++i) {
        memset(visited, 0, sizeof(bool) * n);
        for (int j = 0; j < sns[i].size(); ++j)
            makefriendlist(i, sns[i][j]);
    }

    scanf("%d", &q);
    for (int i = 0, id, f; i < q; ++i) {
        scanf("%d %d", &id, &f);
        if (isfriend(id, f))
            printf("yes\n");
        else
            printf("no\n");
    }

    return 0;
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

vector<int> vec[100010],color(100010,-1);

void dfs(int u){
  if(color[u]==-1) color[u]=u;
  
  stack<int> s;
  s.push(u);
  while(!s.empty()){
    int r=s.top(); s.pop();
    for(auto x:vec[r]){
      if(color[x]==-1){
        color[x]=u;
        s.push(x);
      }
    }
  }
}
  

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