Go: package main

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

var (
	n     int
	G     [100000][]int
	color [100000]*int
)

func dfs(r int, c int) {
	S := Stack{}
	S.Push(r)
	color[r] = &c
	for !S.IsEmpty() {
		u := S.Pop()
		for i := 0; i < len(G[u]); i++ {
			v := G[u][i]
			if color[v] == nil {
				color[v] = &c
				S.Push(v)
			}
		}
	}
}

func assignColor() {
	id := 1
	for i := 0; i < n; i++ {
		color[i] = nil
	}
	for u := 0; u < n; u++ {
		if color[u] == nil {
			id++
			dfs(u, id)
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())

	for i := 0; i < r; i++ {
		sc.Scan()
		s, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		G[s] = append(G[s], t)
		G[t] = append(G[t], s)
	}
	assignColor()
	sc.Scan()
	qNum, _ := strconv.Atoi(sc.Text())
	for i := 0; i < qNum; i++ {
		sc.Scan()
		s, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		if color[s] == color[t] {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

// Stack is Stack
type Stack struct {
	stack []int
}

// Push new value
func (stack *Stack) Push(val int) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() int {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

// IsEmpty return true when stack is empty
func (stack *Stack) IsEmpty() bool {
	return len(stack.stack) == 0
}

Python: import sys
class Union():
    def __init__(self, n):
        self.pre = [i for i in range(n)]
        self.rank = [1 for _ in range(n)]

    def union(self, a, b):
        aroot = self.find(a)
        broot = self.find(b)
        if aroot == broot:
            return
        if self.rank[aroot] < self.rank[broot]:
            aroot, broot = broot, aroot
        self.pre[broot] = self.pre[aroot]
        if self.rank[aroot] == self.rank[broot]:
            self.rank[aroot] += 1

    def find(self, n):
        while self.pre[n] != n:
            n = self.pre[n]
        return n

    def issame(self, a, b):
        if self.find(a) == self.find(b):
            return True
        return False

if __name__ == '__main__':
    m, n = map(int, sys.stdin.readline().split())
    union = Union(m)

    for _ in range(n):
        a, b = map(int, sys.stdin.readline().split())
        union.union(a, b)

    o = int(input())
    for _ in range(o):
        p, q = map(int, sys.stdin.readline().split())
        if union.issame(p, q):
            print('yes')
        else:
            print('no')

Python: def DFS(s):
    flag[s] = 1
    F[group].append(s)
    for i in range(n):
        if G[s][i] == 1:
            if flag[i] == 0:
                DFS(i)
 

n, m = map(int, input().split())
G = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    s, t = map(int, input().split())
    G[s][t] = 1
    G[t][s] = 1

F = []
flag = [0 for i in range(n)]
group = 0
for i in range(n):
    if flag[i] == 0:
        F.append([])
        DFS(i)
        group += 1

q = int(input())
ans = ["no" for i in range(q)]
for i in range(q):
    s, t = map(int, input().split())
    for friends in F:
        if s in friends and t in friends:
            ans[i] = "yes"

for i in range(q):
    print(ans[i])

Python: # -*- coding: utf-8 -*-
from collections import deque

N, M = tuple(map(int, input().split()))
adj = [[0]*(N) for _ in range(N)]

for _ in range(M):
    inp = tuple(map(int, input().split()))
    adj[inp[0]][inp[1]] = 1
    adj[inp[1]][inp[0]] = 1

unsearched = set(range(N))
colors = {n:-1 for n in range(N)}
color = -1
while len(unsearched):
    color += 1
    start = min(unsearched)
    unsearched.remove(start)
    searched = set([start])
    
    que = deque([start])
    while len(que):
        q = que.pop()
        next_ = [i for i in unsearched if adj[q][i]==1 and not (i in searched)]
        searched.update(next_)
        unsearched = unsearched.difference(searched)
        que.extendleft(next_)
    for n in searched:
        colors[n] = color
    
Q = int(input())

for i in range(Q):
    question = tuple(map(int, input().split()))
    if colors[question[0]] == colors[question[1]]:
        print("yes")        
    else:
        print("no")

Python: entry = map(int, raw_input())
n = entry[0]
m = entry[1]
A = [] * n
for i in range(m):
    entry = map(int, raw_input())
    A[entry[0]].append(entry[1])
    A[entry[1]].append(entry[0])

q = int(raw_input())
for i in range(q):
    entry = map(int, raw_input())
    if entry[1] in A[entry[0]]:
        print("yes")
    else:
        print("no")

Python: # -*- coding: utf_8 -*-

level = False
def debug(v):
    if level:
        print(v)

NOT_FOUND = 0
ENQUEUED = 1
FOUND = 2

def bfs(graph, start, target):
    debug(graph)
    if start == target:
        return True
    
    queue = []
    status = [NOT_FOUND] * len(graph)
    queue.append(start)

    while len(queue) != 0:
        debug("----------------------------")
        node = queue.pop(0)
        status[node] = FOUND
        edges = graph[node]
        debug(queue)
        debug(status)
        debug(edges)
        for e in edges:
            if e == target:
                return True
            if status[e] == NOT_FOUND:
                status[e] = ENQUEUED
                queue.append(e)

    return False

if __name__ == "__main__":
    n, m = [int(x) for x in input().split()]

    g = [[] for i in range(n)]
    for i in range(m):
        u, e = [int(x) for x in input().split()]
        g[u].append(e)
        g[e].append(u)

    n = int(input())
    for i in range(n):
        s, d = [int(x) for x in input().split()]
        if bfs(g, s, d):
            print("yes")
        else:
            print("no")

Python: #!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n,m=map(int,input().split())
G=[[]*n for i in range(n)]
color=[-1]*n
for i in range(m):
    v1,v2=map(int,input().split())
    G[v1].append(v2)
    G[v2].append(v1)


def dfs(v,c):
    color[v]=c
    for vi in G[v]:
        if color[vi]==-1:
            dfs(vi,i)


for i in range(n):
    if color[i]==-1:
        dfs(i,i)

q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    print('yes' if color[s]==color[t] else 'no')

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def assign_color():
    _id = 1
    for m in range(vertices_num):
        if vertices_status_list[m] == -1:
            graph_dfs(m, _id)
            _id += 1
    return None


def graph_dfs(vertex, color):
    vertices_stack = list()
    vertices_stack.append(vertex)
    vertices_status_list[vertex] = color
    while vertices_stack:
        current_vertex = vertices_stack[-1]
        vertices_stack.pop()
        for v in adj_list[current_vertex]:
            if vertices_status_list[v] == -1:
                vertices_status_list[v] = color
                vertices_stack.append(v)
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num, relation_num = map(int, _input[0].split())

    relation_info = _input[1:relation_num + 1]

    question_num = int(_input[relation_num + 1])
    question_list = _input[relation_num + 2:]

    adj_list = [[] for _ in range(vertices_num)]
    vertices_status_list = [-1] * vertices_num

    for relation in relation_info:
        key, value = map(int, relation.split())
        adj_list[key].append(value)
        adj_list[value].append(key)

    assign_color()

    # print(adj_list)
    for question in question_list:
        start, target = map(int, question.split())
        if vertices_status_list[start] == vertices_status_list[target]:
            print("yes")
        else:
            print("no")