Go: package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

//util
var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve
const (
	MAX = 100000
	NIL = -1
)

var (
	n, m, q, s, t int
	G             [MAX][]int //連結リスト
	color         [MAX]int
)

func dfs(r int, c int) {
	S := list.New()
	S.PushFront(r)
	color[r] = c
	for S.Len() != 0 {
		u := S.Remove(S.Front()).(int)
		for i := 0; i < len(G[u]); i++ {
			v := G[u][i]
			if color[v] == NIL {
				color[v] = c
				S.PushFront(v)
			}
		}
	}
}

//幅優先探索で、頂点を色付け
func assignColor() {
	id := 1
	for i := 0; i < n; i++ {
		color[i] = NIL
	}
	for i := 0; i < n; i++ {
		if color[i] == NIL {
			id++
			dfs(i, id)
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m = nextInt(), nextInt()
	for i := 0; i < m; i++ {
		s, t = nextInt(), nextInt()
		if i == 0 {
			G[s] = make([]int, 0)
			G[t] = make([]int, 0)
		}
		G[s] = append(G[s], t)
		G[t] = append(G[t], s)

	}
	assignColor()
	q = nextInt()
	for i := 0; i < q; i++ {
		s, t = nextInt(), nextInt()
		if color[s] == color[t] {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}

}

C++: #include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF  (0x7fffffff)
#else
#define LINF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;
/*
void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}
*/
int e[112345][112345]={};
int sumi[112345]={};
int n,m;

int dfs(int v,int g)
{
  int i;
  int ret=0;
  dout(v);
  if(v==g)
    return 1;
  rep(i,n)
    if(e[v][i]==1 && sumi[i]==0)
      {
	sumi[i]=1;
	ret=dfs(i,g);
	if(ret==1)
	  break;
      }
  return ret;
}
int main(void)
{
  int i;
  int a,b;
  int q;
  int s,t;
  cin>>n>>m;
  rep(i,m)
    {
      cin>>a>>b;
      e[a][b]=1;
      e[b][a]=1;
    }
  cin>>q;
  rep(i,q)
    {
      cin>>s>>t;
      if(dfs(s,t))
	cout<<"yes"<<endl;
      else
	cout<<"no"<<endl;
    }    
  return 0;
}

C++: #include <iostream>
#include <map>
#include <queue>
using namespace std;
int main(){
  int n,m,t1,t2;
  map <int,bool> g[100000];
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>t1>>t2;
    g[t1][t2]=1;
    g[t2][t1]=1;
  }
  int l;
  cin>>l;
  for(int i=0;i<l;i++){
    queue <int> q;
    bool f[100000]={},find=false;
    cin>>t1>>t2;
    q.push(t1);
    f[t1]=true;
    for(;!q.empty();){
      for(int j=0;j<n;j++) if(g[q.front()][j]&&!f[j]){
          if(j==t2) find=true;
          f[j]=true;
          q.push(j);
	}
      q.pop();
      if(find) break;
    }
    if(find) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

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

vector<int> ad[100000];
vector<int> v,d;

int main()
{
	int i,j,n,m,a,b,q,l,k;
	queue<int> Q;
	
	cin >> n;
	cin >> m;
	for(i=0;i<=m-1;i++)
	{
		cin >> a;
		cin >> b;
		ad[a].push_back(b);
		ad[b].push_back(a);
	}
	for(i=0;i<=n-1;i++) ad[i].push_back(-1);
	cin >> q;
	for(i=0;i<=q-1;i++)
	{
		cin >> a;
		cin >> b;
		v.clear();
		d.clear();
		for(j=0;j<=n-1;j++)
		{
			v.push_back(0);
			d.push_back(-1);
		}
		v[a]=1;
		d[a]=0;
		Q.push(a);
		while(Q.empty()!=1)
		{
			l=Q.front();
			for(k=0;ad[l][k]!=-1;k++)
			{
				if(v[ad[l][k]]==0)
				{
				    Q.push(ad[l][k]);
				    v[ad[l][k]]=1;
					d[ad[l][k]]=d[l]+1;
				}
			}
			Q.pop();
		}
		if(d[b]>=0) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <stack>
#include <string.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define NOT_FOUND 0
#define ENQUEUED 1
using namespace std;

vector<int> graph[100001];
int memo[100001];

int dfs(int start, int end) {
    if (start == end) {
        return 1;
    }
    memset(memo, NOT_FOUND, sizeof(memo));
    stack<int> stack;
    stack.push(start);
    memo[start] = ENQUEUED;
    int counter = 0;

    while(!stack.empty() && counter != 10) {
        counter += 1;
        int v = stack.top();
        stack.pop();
        vector<int> edges = graph[v];

        for (int i = 0; i < edges.size(); i++) {
            int next = edges[i];
            if (next == end) {
                return 1;
            }
            if (memo[next] == NOT_FOUND) {
                memo[next] = ENQUEUED;
                stack.push(next);
            }
        }
    }
    return 0;
}

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

    for (int i = 0; i < m; i++) {
        int v, e;
        cin >> v >> e;
        graph[v].push_back(e);
        graph[e].push_back(v);
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int s, d;
        cin >> s >> d;
        if (dfs(s, d)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
vi G;
inline int root(int x){ return G[x] < 0 ? x : G[x] = root(G[x]); }
inline void uniteSet(int x, int y){
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (G[x] > G[y]) swap(x, y);
    G[y] = x;
}
inline bool findSet(int x, int y){
	if((x != -1 && y != -1) && (G[x] == G[y])) return true;
	return root(x) == root(y);
}
int main() {
	int n, m; cin >> n >> m;
	G.resize(n, -1);
	int s, t;
	rep(i, 0, m) {
		cin >> s >> t;
		uniteSet(s, t);
	}
	int q; cin >> q;
	rep(i, 0, q) {
		cin >> s >> t;
		P(findSet(s, t) ? "yes" : "no");
	}
	return 0;
}