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

Python: from collections import deque

n, m = map(int, input().split())
g = [set() for _ in range(n)]

while m:
    s, t = map(int, input().split())
    g[s].add(t)
    g[t].add(s)
    m -= 1


def find(s, t):
    global g
    queue = deque()
    queue.append((0, s))
    queue.append((1, t))
    visited = ([0] * n, [0] * n)
    visited[0][s] = 1
    visited[1][t] = 1

    while queue:
        st, i = queue.popleft()
        for f in g[i]:
            if visited[not st][f]:
                g[s].add(t)
                g[t].add(s)
                return True
            if not visited[st][f]:
                visited[st][f] = 1
                queue.append((st, f))
    return False


q = int(input())
while q:
    s, t = map(int, input().split())
    print('yes' if find(s, t) else 'no')
    q -= 1

Python: class UnionSet:
    def __init__(self, num_node: int) -> None:
        self.size = [1] * num_node
        self.id = [i for i in range(num_node + 1)]

    def get_root(self, i: int) -> int:
        while i != self.id[i]:
            self.id[i] = self.id[self.id[i]]
            i = self.id[i]
        return i

    def is_connected(self, node1: int, node2: int) -> bool:
        return self.get_root(node1) == self.get_root(node2)

    def unite(self, node1: int, node2: int) -> None:
        i, j = self.get_root(node1), self.get_root(node2)
        if i == j:
            return
        if self.size[i] < self.size[j]:
            self.id[i] = j
            self.size[j] += self.size[i]
        else:
            self.id[j] = i
            self.size[i] += self.size[j]


if __name__ == "__main__":
    num_users, num_relations = map(lambda x: int(x), input().split())
    union_set = UnionSet(num_users)

    for _ in range(num_relations):
        user1, user2 = map(lambda x: int(x), input().split())
        union_set.unite(user1, user2)

    num_questions = int(input())
    for _ in range(num_questions):
        user1, user2 = map(lambda x: int(x), input().split())
        if union_set.is_connected(user1, user2):
            print("yes")
        else:
            print("no")

Python: def search(s, t, a):
    global g
    a.add(s)
    if s == t:
        return True
    else:
        for ch in g[s]:
            if not (ch in a):
                result = search(ch, t, a)
                if result:
                    return result
        return False

n, m = list(map(int, input().split()))

g = [[] for i in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    g[s].append(t)
    g[t].append(s)

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    a = set()
    result = search(s, t, a)
    if result:
        print("yes")
    else:
        print("no")
    a.clear()

Python: n, m = map(int, input().split())

adj = [[] for i in range(n)]

for i in range(m):
    s, t = map(int, input().split())
    adj[s].append(t)
    adj[t].append(s)

isVisited = [False] * n

CC = [None] * n


def dfs(u, group):
    isVisited[u] = True
    CC[u] = group
    for v in adj[u]:
        if not isVisited[v]:
            dfs(v, group)

def makeCC(group):
    for i in range(n):
        if not isVisited[i]:
            dfs(i, group)
            group += 1

def isConnected(v1, v2):
    if CC[v1] == CC[v2]:
        print('yes')
    else:
        print('no')


makeCC(0)


q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    isConnected(s, t)

Python: n, m = map(int, raw_input().split())
G = [[0 for i in range(n)] for j in range(n)]

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

for i in range(n):
    for j in range(n):
        for k in range(n):
            if G[j][k] == 1:
                for l in range(n):
                    if G[k][l] == 1:
                        G[j][l] = 1
                        G[l][j] = 1

q = int(raw_input())
ans = ["no" for i in range(q)]
for i in range(q):
    s, t = map(int, raw_input().split())
    if G[s][t] == 1:
        ans[i] = "yes"
for i in range(q):
    print(ans[i])

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