class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n



    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            while self.parents[x] >= 0:

                if self.parents[self.parents[x]] >= 0:

                    self.parents[x] = self.parents[self.parents[x]]

                x = self.parents[x]

            return x



    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)



        if x == y:

            return



        if self.parents[x] > self.parents[y]:

            x, y = y, x



        self.parents[x] += self.parents[y]

        self.parents[y] = x



    def size(self, x):

        return -self.parents[self.find(x)]



    def same(self, x, y):

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



    def members(self, x):

        root = self.find(x)

        return [i for i in range(self.n) if self.find(i) == root]



    def roots(self):

        return [i for i, x in enumerate(self.parents) if x < 0]



    def group_count(self):

        return len(self.roots())



    def all_group_members(self):

        return {r: self.members(r) for r in self.roots()}



    def __str__(self):

        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



import sys

input = sys.stdin.buffer.readline

N,Q = list(map(int,input().split()))

uf = UnionFind(N)

for i in range(Q):

    t,u,v = list(map(int,input().split()))

    if t == 0:

        uf.union(u,v)

    else:

        if uf.same(u,v):

            print((1))

        else:

            print((0))

class UnionFind():

    def __init__(self, N):

        self.N = N

        self.parents = [-1] * N



    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            st = []

            while self.parents[x] >= 0:

                st.append(x)

                x = self.parents[x]

            for y in st:

                self.parents[y] = x

            return x



    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)



        if x == y:

            return



        if self.parents[x] > self.parents[y]:

            x, y = y, x



        self.parents[x] += self.parents[y]

        self.parents[y] = x



    def same(self, x, y):

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



import sys

input = lambda:sys.stdin.buffer.readline().rstrip()



N,Q = list(map(int,input().split()))

uf = UnionFind(N)

for i in range(Q):

    t,u,v = list(map(int,input().split()))

    if t:

        print((int(uf.same(u,v))))

    else:

        uf.union(u,v) 
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            while self.parents[x] >= 0:
                if self.parents[self.parents[x]] >= 0:
                    self.parents[x] = self.parents[self.parents[x]]
                x = self.parents[x]
            return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())


import sys

input = sys.stdin.buffer.readline
N, Q = list(map(int, input().split()))
uf = UnionFind(N)
for i in range(Q):
    t, u, v = list(map(int, input().split()))
    if t == 0:
        uf.union(u, v)
    else:
        if uf.same(u, v):
            print((1))
        else:
            print((0))

class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            st = []
            while self.parents[x] >= 0:
                st.append(x)
                x = self.parents[x]
            for y in st:
                self.parents[y] = x
            return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

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


import sys

input = lambda: sys.stdin.buffer.readline().rstrip()
N, Q = list(map(int, input().split()))
uf = UnionFind(N)
for i in range(Q):
    t, u, v = list(map(int, input().split()))
    if t:
        print((int(uf.same(u, v))))
    else:
        uf.union(u, v)

-    def __init__(self, n): -        self.n = n -        self.parents = [-1] * n +    def __init__(self, N): +        self.N = N +        self.parents = [-1] * N +            st = [] -                if self.parents[self.parents[x]] >= 0: -                    self.parents[x] = self.parents[self.parents[x]] +                st.append(x) +            for y in st: +                self.parents[y] = x -    def size(self, x): -        return -self.parents[self.find(x)] - - -    def members(self, x): -        root = self.find(x) -        return [i for i in range(self.n) if self.find(i) == root] - -    def roots(self): -        return [i for i, x in enumerate(self.parents) if x < 0] - -    def group_count(self): -        return len(self.roots()) - -    def all_group_members(self): -        return {r: self.members(r) for r in self.roots()} - -    def __str__(self): -        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) -input = sys.stdin.buffer.readline +input = lambda: sys.stdin.buffer.readline().rstrip() -    if t == 0: +    if t: +        print((int(uf.same(u, v)))) +    else: -    else: -        if uf.same(u, v): -            print((1)) -        else: -            print((0))