import sys

 

f_i = sys.stdin

 

n, q = list(map(int, f_i.readline().split()))



class DisjointSets:

    def __init__(self, size):

        self.size = size

        self.representatives = list(range(size))



    def _find(self, x):

        return self.representatives[x]



    def union(self, x, y):

        x1 = self._find(x)

        y1 = self._find(y)

        if x1 == y1:

            return None

        # unite Sx and Sy

        for i in range(self.size):

            if self.representatives[i] == y1:

                self.representatives[i] = x1



    def isSameSet(self, x, y):

        if self._find(x) == self._find(y):

            print((1))

        else:

            print((0))



S = DisjointSets(n)



for l in f_i:

    com, x, y = list(map(int, l.split()))

    if com == 0:

        S.union(x, y)

    else:

        S.isSameSet(x, y)
import sys



f_i = sys.stdin



n, q = list(map(int, f_i.readline().split()))



class DisjointSets:

    def __init__(self, size):

        # negative values are roots(representatives of each tree)

        # positive values represent the parent element

        self.table = [-1 for _ in range(size)]



    def _find(self, x):

        if self.table[x] < 0:

            return x

        else:

            # compression of the path

            self.table[x] = self._find(self.table[x])

            return self.table[x]



    def uniteSets(self, x, y):

        s1 = self._find(x)

        s2 = self._find(y)

        if s1 != s2:

            if self.table[s1] < self.table[s2]: # the smaller has more elements

                self.table[s1] += self.table[s2]

                self.table[s2] = s1

            else:

                self.table[s2] += self.table[s1]

                self.table[s1] = s2



    def isSameSet(self, x, y):

        if self._find(x) == self._find(y):

            print((1))

        else:

            print((0))



S = DisjointSets(n)



for l in f_i:

    com, x, y = list(map(int, l.split()))

    if com == 0:

        S.uniteSets(x, y)

    else:

        S.isSameSet(x, y)
import sys

f_i = sys.stdin
n, q = list(map(int, f_i.readline().split()))


class DisjointSets:
    def __init__(self, size):
        self.size = size
        self.representatives = list(range(size))

    def _find(self, x):
        return self.representatives[x]

    def union(self, x, y):
        x1 = self._find(x)
        y1 = self._find(y)
        if x1 == y1:
            return None
        # unite Sx and Sy
        for i in range(self.size):
            if self.representatives[i] == y1:
                self.representatives[i] = x1

    def isSameSet(self, x, y):
        if self._find(x) == self._find(y):
            print((1))
        else:
            print((0))


S = DisjointSets(n)
for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        S.union(x, y)
    else:
        S.isSameSet(x, y)

import sys

f_i = sys.stdin
n, q = list(map(int, f_i.readline().split()))


class DisjointSets:
    def __init__(self, size):
        # negative values are roots(representatives of each tree)
        # positive values represent the parent element
        self.table = [-1 for _ in range(size)]

    def _find(self, x):
        if self.table[x] < 0:
            return x
        else:
            # compression of the path
            self.table[x] = self._find(self.table[x])
            return self.table[x]

    def uniteSets(self, x, y):
        s1 = self._find(x)
        s2 = self._find(y)
        if s1 != s2:
            if self.table[s1] < self.table[s2]:  # the smaller has more elements
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2

    def isSameSet(self, x, y):
        if self._find(x) == self._find(y):
            print((1))
        else:
            print((0))


S = DisjointSets(n)
for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        S.uniteSets(x, y)
    else:
        S.isSameSet(x, y)

-        self.size = size -        self.representatives = list(range(size)) +        # negative values are roots(representatives of each tree) +        # positive values represent the parent element +        self.table = [-1 for _ in range(size)] -        return self.representatives[x] +        if self.table[x] < 0: +            return x +        else: +            # compression of the path +            self.table[x] = self._find(self.table[x]) +            return self.table[x] -    def union(self, x, y): -        x1 = self._find(x) -        y1 = self._find(y) -        if x1 == y1: -            return None -        # unite Sx and Sy -        for i in range(self.size): -            if self.representatives[i] == y1: -                self.representatives[i] = x1 +    def uniteSets(self, x, y): +        s1 = self._find(x) +        s2 = self._find(y) +        if s1 != s2: +            if self.table[s1] < self.table[s2]:  # the smaller has more elements +                self.table[s1] += self.table[s2] +                self.table[s2] = s1 +            else: +                self.table[s2] += self.table[s1] +                self.table[s1] = s2 -        S.union(x, y) +        S.uniteSets(x, y)