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: V, E = map(int, input().split())
edge = [[] for _ in range(V)]
for _ in range(E):
    s, t = map(int, input().split())
    edge[s].append(t)
    edge[t].append(s)

group = [-1] * V
cnt = 0
for i in range(V):
    if group[i] == -1:
        group[i] = cnt
        stack = [i]
        while stack:
            v = stack.pop()
            for c in edge[v]:
                if group[c] == -1:
                    group[c] = cnt
                    stack.append(c)
        cnt += 1
for _ in range(int(input())):
    s, t = map(int, input().split())
    print('yes' if group[s] == group[t] else 'no')

Python: def warshall_floyd(w):
    inf = 1E+100
    n = len(w)
    d = w
    for k in range(n):
        d_new = [[inf for _ in range(n)] for _ in range(n)]
        for i in range(n):
            for j in range(n):
                d_new[i][j] = min(d[i][j], d[i][k] + d[k][j])
        d = d_new
    return d


inf = 1E+100
s = [int(x) for x in input().split()]
n = s[0]
m = s[1]
w = [[inf for _ in range(n)] for _ in range(n)]
for i in range(n):
    w[i][i] = 0
for _ in range(m):
    s = [int(x) for x in input().split()]
    w[s[0]][s[1]] = 1
    w[s[1]][s[0]] = 1

d = warshall_floyd(w)

q = int(input())
for _ in range(q):
    s = [int(x) for x in input().split()]
    u = s[0]
    v = s[1]
    if d[u][v] < inf:
        print("yes")
    else:
        print("no")

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

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

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

unsearched = set(range(N))
colors = {n:-1 for n in range(N)}
color = -1

for n in range(N):
    if colors[n] != -1:
        continue
    color += 1
    start = n
    
    que = deque([start])
    while len(que):
        q = que.pop()
        next_ = [i for i in adj[q] if colors[i] == -1]
        que.extendleft(next_)
        colors[q] = 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: from collections import deque

V, E = map(int, input().split())
Edge = [[] for _ in range(V)]

for _ in range(E): #??£????????????
    u, v = map(int, input().split())
    Edge[u].append(v)
    Edge[v].append(u)
    
Group = [-1] * V #Group???????????????????????°?????????????±????????????????????????°?????????????????°??????????????????????????????
Cnt = 0 # Group???????????????????±????????????????

for i in range(V):
    if Group[i] == -1:
        Group[i] = Cnt
        Stack = deque([i])
        while Stack:
            v = Stack.pop()
            for c in Edge[v]:
                if Group[c] == -1:
                    Group[c] = Cnt
                    Stack.append(c)
        Cnt += 1

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

Python: #coding:utf-8
n, r = map(int,input().split())
Q = []
M = [[] for j in range(n)]
for i in range(r):
    i,j = map(int,input().split())
    M[i].append(j)
    M[j].append(i)


def search(person, target):
    data = M[person]
    for per in data:
        if per ==  target:
            global yes
            yes = 1
            print("yes")
            return
        if color[per] == "white":
            color[per] = "gray"
            search(per, target)
    color[person] = "black"

num = int(input())
for i in range(num):
    yes = 0
    color = ["white" for j in range(n)]
    person, target = map(int,input().split())
    search(person, target)
    if yes == 0:
        print("no")

Python: def dfs(r, c, g, color):
    s = [r]
    color[r] = c
    while len(s) != 0:
        u = s.pop()
        for i in range(len(g[u])):
            v = g[u][i]
            if color[v] is None:
                color[v] = c
                s.append(v)


def assignColor(n, g, color):
    color_id = 1
    for u in range(n):
        if color[u] is None:
            dfs(u, color_id, g, color)
            color_id += 1


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

color = [None] * n
assignColor(n, g, color)

q = int(input())

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