Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)
	nConns := scanInt(sc)

	graph := make([][]int, nNodes)
	for i := 0; i < nConns; i++ {
		a, b := scanInt(sc), scanInt(sc)
		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}

	groups := make([]int, nNodes)

	var setGroups func(int, int)
	setGroups = func(u int, groupId int) {
		if groups[u] > 0 {
			return
		}
		groups[u] = groupId

		for _, v := range graph[u] {
			setGroups(v, groupId)
		}
	}
	for i := 0; i < nNodes; i++ {
		setGroups(i, i+1)
	}

	nQuestions := scanInt(sc)

	w := bufio.NewWriter(os.Stdout)
	var ans string
	for i := 0; i < nQuestions; i++ {
		a, b := scanInt(sc), scanInt(sc)
		if groups[a] == groups[b] {
			ans = "yes"
		} else {
			ans = "no"
		}
		fmt.Fprintln(w, ans)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

Python: from collections import deque

def bfs(graph, start, goal, connection):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        if now == goal or goal in connection[now]:
            connection[start].add(goal)
            connection[goal].add(start)
            return "yes"
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return "no"

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

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)
    c[a].add(b)
    c[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    print(bfs(g, s, t, c))

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