Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func newGraph(nNodes int) *Graph {
	g := Graph{}
	g.nodes = make([]*GraphNode, nNodes)
	for iNode := 0; iNode < len(g.nodes); iNode++ {
		g.nodes[iNode] = &GraphNode{}
		g.nodes[iNode].key = GraphNodeKey(iNode)
	}
	return &g
}

var infty = 1000000000

type GraphNodeKey int

// GraphNode is a node for undirected graph
type GraphNode struct {
	key       GraphNodeKey
	adjacents []*GraphNode
	visited   bool
	d, f      int
	parent    *GraphNode
	cc        int
}

func (g *Graph) setAdjacent(l, r GraphNodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

// Graph is a undirected graph
type Graph struct {
	nodes []*GraphNode
}

func (g *Graph) initialize() {
	for iNode := 0; iNode < len(g.nodes); iNode++ {
		g.nodes[iNode].visited = false
		g.nodes[iNode].d = infty
		g.nodes[iNode].f = infty
		g.nodes[iNode].parent = nil
		g.nodes[iNode].cc = -1 // 22.3-12
	}
}

type QueueEntry struct {
	node *GraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *GraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *Graph) {
	g.initialize()
	time = 0
	cc := 0

	for _, u := range g.nodes {
		if !u.visited {
			dfsVisit(g, u, cc)
			cc++
		}
	}
}

func dfsVisit(g *Graph, u *GraphNode, cc int) {
	time++
	u.d = time
	u.cc = cc

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v, cc)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nUsers := nextInt()
	nEdges := nextInt()
	graph := newGraph(nUsers)
	for iEdge := 0; iEdge < nEdges; iEdge++ {
		l := GraphNodeKey(nextInt())
		r := GraphNodeKey(nextInt())
		graph.setAdjacent(l, r)
		graph.setAdjacent(r, l)
	}

	fillDistancesByDepthFirstSearch(graph)

	nQueries := nextInt()
	for iQuery := 0; iQuery < nQueries; iQuery++ {
		l := GraphNodeKey(nextInt())
		r := GraphNodeKey(nextInt())

		// fmt.Println(graph.nodes[l].d, graph.nodes[r].d, graph.nodes[r].f, graph.nodes[l].f)
		if graph.nodes[l].cc == graph.nodes[r].cc {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

C++: #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

struct node {
	int id;
	vector<int> rel;
};

int n, m, q;
node* nodes;

/* DFS * TLE! *
bool canReach(int s, int d, bool* h){
	h[s] = true;
	for(int i = 0; i < nodes[s].rel.size(); i++){
		if(nodes[s].rel[i] == d) return true;
		else if(!h[nodes[s].rel[i]]){
			if(canReach(nodes[s].rel[i], d, h)) return true;
		}
	}
	return false;
}
*/

int main() {
	scanf("%d %d", &n, &m);
	
	nodes = new node[n];
	for(int i = 0; i < n; i++){
		nodes[i].id = i;
	}
	while(m--){
		int l, r;
		scanf("%d %d", &l, &r);
		nodes[l].rel.push_back(r);
		nodes[r].rel.push_back(l);
	}
	
	scanf("%d", &q);
	while(q--){
		int l, r;
		scanf("%d %d", &l, &r);
		
		bool *h = new bool[n];
		for(int i = 0; i < n; i++){
			h[i] = false;
		}
		
		queue<int> qu;
		qu.push(l);
		while(qu.size()){
			h[qu.front()] = true;
			for(int i = 0; i < nodes[qu.front()].rel.size(); i++){
				if(nodes[qu.front()].rel[i] == r){
					puts("yes");
					goto BREAK;
				}else if(!h[nodes[qu.front()].rel[i]]){
					qu.push(nodes[qu.front()].rel[i]);
				}
			}
			qu.pop();
		}
		puts("no");
		BREAK:;
		delete[] h;
	}
	return 0;
}

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

const int INF=99999999;

vector<int> A[100000];

void get_network(int N,int M){
    int s,t;
    for(int i=0;i<M;i++){
        cin>>s>>t;
        A[s].push_back(t);
        A[t].push_back(s);
    }
}
void bfs(int n,int v,vector<int>& flag,int mark){
        queue<int> Q;
        flag[v]=mark;
        for(int i=0;i<A[v].size();i++){
                Q.push(A[v][i]);
        }
        while(!Q.empty()){
                int u=Q.front();
                flag[u]=mark;
                for(int i=0;i<A[u].size();i++){
                        if(flag[A[u][i]]==-1){
                                Q.push(A[u][i]);
                        }
                }
                Q.pop();
        }
}

int main(){
        int n,m;
        scanf("%d %d\n",&n,&m);
        get_network(n,m);

        vector<int> flag(n,-1);
        int colored=-1;
        int v=0;
        int mark=0;
        while(colored!=0){
                mark++;
                bfs(n,v,flag,mark);
                colored=0;
                for(int i=0;i<flag.size();i++){
                    if(flag[i]==-1){
                        v=i;
                        colored=1;
                        break;
                    }
                }
        }

        int q,s,t;
        scanf("%d\n",&q);

        for(int i=0;i<q;i++){
                scanf("%d %d\n",&s,&t);
                if(flag[s]==flag[t]){
                        printf("yes\n");
                }else{
                        printf("no\n");
                }
        }
        return 0;
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#define N 100000
using namespace std;


int C[N];
queue<int> k;
vector<int> v[N];
void color(int);
bool search(int,int);

int main(){
	int n,m,a,b,q;
	cin >> n >>m;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	cin >> q;
	for(int i=0;i<n;i++){
		C[i]=-1; //?????????
	}
	for(int i=0;i<n;i++){
		if(C[i]==-1)color(i); //i????§??????¨????????±???
	}
	for(int i=0;i<q;i++){
		cin>>a>>b;
		if(search(a,b)) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

bool search(int a,int b){
	if(C[a]==C[b]) return true;
	else return false;
}

void color(int a){
	static int c=0;
	c++;
	C[a]=c;
	k.push(a);
	while(!k.empty()){
		int m = k.front();
		k.pop();
		for(int i=0;i<v[m].size();i++){
			int Z= v[m].at(i);
			if(C[Z]==-1){
				C[Z]=c;
				k.push(Z);
			}
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
using namespace std;

int n, m;
int d[100000];
int t = 0;
int c[100000];
queue<int> q;
vector<int> v[100000];
int ans = 2;

void bfs(int u){
  q.push(u);
  c[u] = 1;

  while(q.empty() == 0){
    u = q.front();
    q.pop();
    for(int i = 0; i < v[u].size(); i++){
      if(c[v[u][i]] == 0){
        q.push(v[u][i]);
        c[v[u][i]] = 1;
      }

    }
    c[u] = ans;
  }

}


int main(){

  cin >> n;

  for(int i = 0; i < n; i++){
    c[i] = 0;
  }

  cin >> m;

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

  for(int i = 0; i < n; i++){
    if(c[i] == 0){
      bfs(i);
      ans++;
    }
  }

  int q;
  cin >> q;

  for(int i = 0; i < q; i++){
    int x, y;
    cin >> x >> y;
    if(c[x] == c[y]) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}