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

Python: #coding: utf-8
n, m = map(int,input().split())
List = [[] for i in range(n)]
color = ["white" for i in range(n)]

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


def search(a,target):
    for member in List[a]:
        if member == target:
            print("yes")
            return True
        if color[member] == "white":
            color[member] = "black"
            return search(member, target)

p = int(input())
for i in range(p):
    a, target = map(int,input().split())
    b = search(a, target)
    if b != True:
        print("no")

Python: V,E = map(int,input().split())
 
boss = [i for i in range(V)]
height = [0 for i in range(V)]
 
def get_boss(index):
    if index == boss[index]:
        return index
    else:
        boss[index] = get_boss(boss[index])
        return boss[index]
 
 
def is_same_group(a,b):
    return get_boss(a) == get_boss(b)
 
def unite(x,y):
    boss_x = get_boss(x)
    boss_y = get_boss(y)
 
    if boss_x == boss_y:
        return
 
    if height[x] > height[y]:
 
        boss[boss_y] = boss_x
 
    elif height[x] < height[y]:
 
        boss[boss_x] = boss_y
 
    else:
        boss[boss_y] = boss_x
        height[x] += 1
 
 
for loop in range(E):
    A,B = map(int,input().split())
    unite(A,B)
 
num_query = int(input())
 
for loop in range(num_query):
    A,B = map(int,input().split())
    if is_same_group(A,B) == True:
        print("yes")
    else:
        print("no")

Python: from collections import deque

c=1        #cc count

def dfs(t):
    s=deque()
   
    global c

    s.append(t)
    color[t] = c
    while (len(s)!=0): 
        u = s.pop()
        lens = len(G[u])
        for i in range(lens) :
            v = G[u][i]
            if (flag[v] == 0) :
                color[v] = c
                flag[v] = 1
                s.append(v)
            
            
n,ln=[int(x) for x in input().split()]
maxx=n+10
m=[[0 for col in range(maxx)] for row in range(maxx)] 
G=[[] for row in range(maxx)]
color=[0 for col in range(maxx)]
flag=[0 for col in range(maxx)]



for i in range(ln):
    u,v=[int(x) for x in input().split()]
    G[u].append(v)
    G[v].append(u)

for i in range(n):
    if (flag[i] == 0):
            dfs(i)
            c+=1
        
q=int(input())
for i in range(q):
    u,v=[int(x) for x in input().split()]
    if (color[u] == color[v]):
        print("yes")
    else:
        print("no")

Python: def scanu(t):
    a = list(map(t,input().split()))
    return a

def breathSerch(P,N,start):
    n=len(P)-1
    m=1
    QQ=[N[start]]
    while(QQ != []):
        R=[]
        for Q in QQ:
            for i in range(1,n+1):
                if Q[i]==1 and P[i]==-1:
                    P[i]=m
                    R.append(N[i])
        QQ = R
        m=m+1

(n,m) = scanu(int)
A = [[0 for j in range(n+1)] for i in range(n+1)]
for i in range(m):
    (s,t)= scanu(int)
    A[s+1][t+1]=1
    A[t+1][s+1]=1

q = int(input())

for i in range(q):
    (s,t) = scanu(int)
    P=[-1 for i in range(n+1)]
    P[s+1]=0
    breathSerch(P,A,s+1)
    if P[t+1]!=-1:
        print("yes")
    else:
        print("no")

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

def are_connected(s, t):
    q = [s]
    checked = [False] * n
    checked[s] = True

    while q:
        user = q.pop(0)
        for f in friend[user]:
            if f == t:
                return True
            elif not checked[f]:
                q.append(f)
                checked[f] = True
    return False

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

Python: def read_friends():
    n, m = [int(x) for x in input().split()]
    adj_list = [set() for _ in range(n)]

    for _ in range(m):
        s, t = [int(x) for x in input().split()]
        adj_list[s].add(t)
        adj_list[t].add(s)

    return n, adj_list


def divide_group(n, adj_list):
    group = [None] * n

    def visit(k, g):
        S = [k]

        while S:
            k = S.pop()
            group[k] = g
            for t in adj_list[k]:
                if group[t] is None:
                    S.append(t)

    for k in range(n):
        if group[k] is None:
            visit(k, k)

    return group


def answer_queries(group):
    q = int(input())

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


def main():
    n, adj_list = read_friends()
    group = divide_group(n, adj_list)
    answer_queries(group)


if __name__ == '__main__':
    main()