import sys

sys.setrecursionlimit(10**6)





class UnionFindTree:

    """Disjoint-Set Data Structure

       Union-Find Tree

       complexity:

          init: O(n)

          find, unite, same: O(alpha(n))

       used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ)

    """

    def __init__(self, n):

        self.par = list(range(n))  # parent

        self.rank = [0] * n  # depth of tree



    def find(self, x):

        if self.par[x] == x:

            return x

        else:

            self.par[x] = self.find(self.par[x])

            return self.par[x]



    def unite(self, x, y):

        x, y = self.find(x), self.find(y)

        if x == y:

            return

        if self.rank[x] < self.rank[y]:

            self.par[x] = y

        else:

            self.par[y] = x

            if self.rank[x] == self.rank[y]:

                self.rank[x] += 1



    def same(self, x, y):

        return self.find(x) == self.find(y)



V, E = list(map(int, input().split()))

uf = UnionFindTree(V)

for _ in range(E):

    uf.unite(*list(map(int, input().split())))

for _ in range(int(eval(input()))):

    print(('yes' if uf.same(*list(map(int, input().split()))) else 'no'))
V, E = list(map(int, input().split()))

edge = [[] for _ in range(V)]

for _ in range(E):

    s, t = list(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(eval(input()))):

    s, t = list(map(int, input().split()))

    print(('yes' if group[s] == group[t] else 'no'))
import sys

sys.setrecursionlimit(10**6)


class UnionFindTree:
    """Disjoint-Set Data Structure
    Union-Find Tree
    complexity:
       init: O(n)
       find, unite, same: O(alpha(n))
    used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ)
    """

    def __init__(self, n):
        self.par = list(range(n))  # parent
        self.rank = [0] * n  # depth of tree

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


V, E = list(map(int, input().split()))
uf = UnionFindTree(V)
for _ in range(E):
    uf.unite(*list(map(int, input().split())))
for _ in range(int(eval(input()))):
    print(("yes" if uf.same(*list(map(int, input().split()))) else "no"))

V, E = list(map(int, input().split()))
edge = [[] for _ in range(V)]
for _ in range(E):
    s, t = list(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(eval(input()))):
    s, t = list(map(int, input().split()))
    print(("yes" if group[s] == group[t] else "no"))

-import sys - -sys.setrecursionlimit(10**6) - - -class UnionFindTree: -    """Disjoint-Set Data Structure -    Union-Find Tree -    complexity: -       init: O(n) -       find, unite, same: O(alpha(n)) -    used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ) -    """ - -    def __init__(self, n): -        self.par = list(range(n))  # parent -        self.rank = [0] * n  # depth of tree - -    def find(self, x): -        if self.par[x] == x: -            return x -        else: -            self.par[x] = self.find(self.par[x]) -            return self.par[x] - -    def unite(self, x, y): -        x, y = self.find(x), self.find(y) -        if x == y: -            return -        if self.rank[x] < self.rank[y]: -            self.par[x] = y -        else: -            self.par[y] = x -            if self.rank[x] == self.rank[y]: -                self.rank[x] += 1 - -    def same(self, x, y): -        return self.find(x) == self.find(y) - - -uf = UnionFindTree(V) +edge = [[] for _ in range(V)] -    uf.unite(*list(map(int, input().split()))) +    s, t = list(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 -    print(("yes" if uf.same(*list(map(int, input().split()))) else "no")) +    s, t = list(map(int, input().split())) +    print(("yes" if group[s] == group[t] else "no"))