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)
	}
}

Python: n,m = map(int,input().split())
B = [[0 for i in range(n)] for j in range(n)]
chk = [0 for i in range(n)]
s = []
i_array = [0 for i in range(n)]
connect = []
cou = 0
node_in = [0 for i in range(n)]

for i in range(m):
    A = list(map(int,input().split()))
    B[A[0]][A[1]] = 1
    B[A[1]][A[0]] = 1

for i in range(n):
    if(chk[i] == 1):
        continue
    chk[i] = 1
    s.append(i)
    connect.append([])
    connect[cou].append(i)
    node_in[i] = cou

    while(len(s) != 0):
        flag = 0
        v = s[len(s)-1]
        for j in range(i_array[v],n):
            if(B[v][j] == 1 and chk[j] == 0):
                chk[j] = 1
                s.append(j)
                connect[cou].append(j)
                node_in[j] = cou
                i_array[v] = j+1
                flag = 1
                break
        if(flag == 0):
            s.pop()

    cou += 1

q = int(input())
for i in range(q):
    start,target = map(int,input().split())
    p = node_in[start]
    flag = 0
    for j in range(len(connect[p])):
        if(connect[p][j] == target):
            print("yes")
            flag = 1
            break
    if(flag == 0):
        print("no")

Python: def tan(G,st,fi):
    global flag
    global flag_list
    for i in range(len(G)):
        if flag_list[i] == 1:
            continue
        if G[st][i] == 1:
            if i == fi:
                flag = 1
            flag_list[i] = 1
            tan(G,i,fi)
    
n,m = list(map(int, input().split()))
G = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    S = list(map(int, input().split()))
    G[S[0]][S[1]] = 1
    G[S[1]][S[0]] = 1

q = int(input())
ans = []
for i in range(q):
    Q = list(map(int, input().split()))
    flag = 0
    flag_list = [0 for i in range(n)]
    tan(G,Q[0],Q[1])
    if flag==1:
        ans.append("yes")
    else:
        ans.append("no")
        
for i in range(q):
    print(ans[i])

Python: def connected(G,s,t):
    checked = [False]*len(G)
    def main(G,s,t):
        if t in G[s]: return True
        checked[s] = True
        for f in G[s]:
            if checked[f]: continue
            if main(G,f,t): return True
        return False
    return main(G,s,t)


if __name__=='__main__':
    n,m = list(map(int,input().split()))
    G = [[] for _ in range(n)]
    for _ in range(m):
        s,t = list(map(int,input().split()))
        G[s].append(t)
        G[t].append(s)
    q = int(input())
    for _ in range(q):
        s,t = list(map(int,input().split()))
        print('Yes' if connected(G,s,t) else 'No')

Python: import sys


if __name__ == "__main__":
    n, m = map(int, sys.stdin.readline().split())
    setlist = []
    inp = sys.stdin.readlines()
    for i in range(m):
        inp_i = list(map(int, inp[i].split()))
        a = -1
        b = -1
        for j in range(len(setlist)):
            if inp_i[0] in setlist[j]:
                a = j
            if inp_i[1] in setlist[j]:
                b = j
        if a == -1 and b == -1:
            setlist.append(set([inp_i[0], inp_i[1]]))
        elif a == -1:
            setlist[b].add(inp_i[0])
        elif b == -1:
            setlist[a].add(inp_i[1])
        elif a < b:
            c = setlist.pop(a)
            d = setlist.pop(b-1)
            e = c.union(d)
            setlist.append(e)
        elif a > b:
            c = setlist.pop(b)
            d = setlist.pop(a-1)
            e = c.union(d)
            setlist.append(e)
    for i in range(int(inp[m])):
        inp_i = list(map(int, inp[i+m+1].split()))
        if len(setlist) == 0:
            print("no")
        for j in range(len(setlist)):
            if inp_i[0] in setlist[j]:
                if inp_i[1] in setlist[j]:
                    print("yes")
                    break
                else:
                    print("no")
                    break
            if j == len(setlist)-1:
                print("no")

Python: def tan(G,st,fi,flag):
    for i in range(len(G)):
        if G[st][i] == 1:
            print(st,fi,i)
            if i == fi:
                flag == 1
            tan(G,i,fi,flag)
    
n,m = list(map(int, input().split()))
G = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    S = list(map(int, input().split()))
    G[S[0]][S[1]] = 1

q = int(input())
ans = []
for i in range(q):
    Q = list(map(int, input().split()))
    st = Q[0]
    fi = Q[1]
    flag = 0
    tan(G,Q[0],Q[1],flag)
    if flag==1:
        ans.append("yes")
    else:
        ans.append("no")
        
for i in range(q):
    print(ans[i])

Python: from collections import deque
n,m = [int(i) for i in input().split()]
F = [{} for i in range(n)]
for _ in range(m):
    i,j = [int(i) for i in input().split()]
    F[i][j] = 1
    F[j][i] = 1
q = int(input())
DP = [0 for i in range(n)]
c = 1
d = deque()
for i in range(n):
    if DP[i]:
        continue
    else:
        d.append(i)
    while(len(d)>0):
        tmp = d.pop()
        DP[tmp] = c
        for i in F[tmp]:
            if not DP[i]:
                d.append(i)
    c+=1

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

Python: # -*- coding: utf-8 -*-
import sys


def assignColor():
    for i in range(n):
        if C[i] == -1:
            #BFS(i)
            DFS(i)

def BFS(start):
    global C
    Q = [start]
    C[start] = start

    while len(Q) != 0:
        u = Q.pop(0)
        v = [i for i in G[u] if C[i] == -1] # v := ??£??\???????????????????????¢?´¢??????????????????
        
        for i in v:
            Q.append(i)
            C[i] = C[start]

#@profile
def DFS(start):
    S = [start]
    C[start] = start
    while len(S) != 0:
        u = S.pop(0)
        for i in G[u]:
            if C[i] == -1:
                C[i] = start
                S.append(i)

if __name__ == "__main__":
    _input = sys.stdin.readlines()
    n, m = list(map(int, _input[0].split()))
    G = [[] for i in range(n)]
    C = [-1]*n
    
    for i in range(m):
        s, t = list(map(int, _input[i+1].split()))
        G[s].append(t)
        G[t].append(s)
    assignColor()
    q = int(_input[m+1])
    for i in range(q):
        s, t = list(map(int, _input[m+i+2].split()))
        if C[s] == C[t]:
            print("yes")
        else:
            print("no")