#! python3

# disjoint_set_union_find_tree.py



n, q = [int(x) for x in input().split(' ')]



sets = [set([i]) for i in range(n)]



def unite(Sx, Sy):

    return Sx | Sy



def search(x):

    global sets

    flag = False

    for i in range(len(sets)):

        if x in sets[i]:

            flag = True

            break

    if flag:

        return i

    else:

        return None



def same(x, y):

    global sets

    flag = 0

    for set in sets:

        if x in set:

            if y in set:

                 flag = 1

            break

    return flag



for i in range(q):

    query, x, y = input().split(' ')

    x, y = int(x), int(y)

    if query == '0':

        # unite

        i_x = search(x)

        i_y = search(y)

        if i_x != None and i_y != None and i_x != i_y:

            sets[i_x] = unite(sets[i_x], sets[i_y])

            del sets[i_y]

    elif query == '1':

        # same

        print((same(x, y)))

#! python3

# disjoint_set_union_find_tree.py



class UnionFindTree():

    def __init__(self, n):

        self.par = [i for i in range(n+1)]

        self.rank = [0] * (n+1)



    def find(self, x):

        if self.par[x] == x:

            return x

        else:

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

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



    def unite(self, x, y):

        x = self.find(x)

        y = self.find(y)

        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_check(self, x, y):

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



n, q = [int(x) for x in input().split(' ')]

uft = UnionFindTree(n-1)



for i in range(q):

    com, x, y = [int(x) for x in input().split(' ')]

    if com == 0:

        uft.unite(x, y)

    elif com == 1:

        if uft.same_check(x, y):

            print((1))

        else:

            print((0))



#! python3
# disjoint_set_union_find_tree.py
n, q = [int(x) for x in input().split(" ")]
sets = [set([i]) for i in range(n)]


def unite(Sx, Sy):
    return Sx | Sy


def search(x):
    global sets
    flag = False
    for i in range(len(sets)):
        if x in sets[i]:
            flag = True
            break
    if flag:
        return i
    else:
        return None


def same(x, y):
    global sets
    flag = 0
    for set in sets:
        if x in set:
            if y in set:
                flag = 1
            break
    return flag


for i in range(q):
    query, x, y = input().split(" ")
    x, y = int(x), int(y)
    if query == "0":
        # unite
        i_x = search(x)
        i_y = search(y)
        if i_x != None and i_y != None and i_x != i_y:
            sets[i_x] = unite(sets[i_x], sets[i_y])
            del sets[i_y]
    elif query == "1":
        # same
        print((same(x, y)))

#! python3
# disjoint_set_union_find_tree.py
class UnionFindTree:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        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_check(self, x, y):
        return self.find(x) == self.find(y)


n, q = [int(x) for x in input().split(" ")]
uft = UnionFindTree(n - 1)
for i in range(q):
    com, x, y = [int(x) for x in input().split(" ")]
    if com == 0:
        uft.unite(x, y)
    elif com == 1:
        if uft.same_check(x, y):
            print((1))
        else:
            print((0))

-n, q = [int(x) for x in input().split(" ")] -sets = [set([i]) for i in range(n)] +class UnionFindTree: +    def __init__(self, n): +        self.par = [i for i in range(n + 1)] +        self.rank = [0] * (n + 1) + +    def find(self, x): +        if self.par[x] == x: +            return x +        else: +            self.par[x] = self.find(self.par[x]) +            return self.find(self.par[x]) + +    def unite(self, x, y): +        x = self.find(x) +        y = self.find(y) +        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_check(self, x, y): +        return self.find(x) == self.find(y) -def unite(Sx, Sy): -    return Sx | Sy - - -def search(x): -    global sets -    flag = False -    for i in range(len(sets)): -        if x in sets[i]: -            flag = True -            break -    if flag: -        return i -    else: -        return None - - -def same(x, y): -    global sets -    flag = 0 -    for set in sets: -        if x in set: -            if y in set: -                flag = 1 -            break -    return flag - - +n, q = [int(x) for x in input().split(" ")] +uft = UnionFindTree(n - 1) -    query, x, y = input().split(" ") -    x, y = int(x), int(y) -    if query == "0": -        # unite -        i_x = search(x) -        i_y = search(y) -        if i_x != None and i_y != None and i_x != i_y: -            sets[i_x] = unite(sets[i_x], sets[i_y]) -            del sets[i_y] -    elif query == "1": -        # same -        print((same(x, y))) +    com, x, y = [int(x) for x in input().split(" ")] +    if com == 0: +        uft.unite(x, y) +    elif com == 1: +        if uft.same_check(x, y): +            print((1)) +        else: +            print((0))