import sys

 

f_i = sys.stdin

 

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

 

S = set(frozenset([i]) for i in range(n))

 

def unite(sets, v1, v2):

    s1 = None

    s2 = None

    for s in sets:

        if v1 in s and v2 in s:

            return None

        elif v1 in s:

            s1 = s

        elif v2 in s:

            s2 = s

        if s1 and s2:

            break

    sets.discard(s1)

    sets.discard(s2)

    s3 = s1.union(s2)

    sets.add(s3)

 

def same(sets, v1, v2):

    for s in sets:

        if v1 in s and v2 in s:

            print((1))

            break

        elif v1 in s or v2 in s:

            print((0))

            break

 

for l in f_i:

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

    if com == 0:

        unite(S, x, y)

    else:

        same(S, 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()))
S = set(frozenset([i]) for i in range(n))


def unite(sets, v1, v2):
    s1 = None
    s2 = None
    for s in sets:
        if v1 in s and v2 in s:
            return None
        elif v1 in s:
            s1 = s
        elif v2 in s:
            s2 = s
        if s1 and s2:
            break
    sets.discard(s1)
    sets.discard(s2)
    s3 = s1.union(s2)
    sets.add(s3)


def same(sets, v1, v2):
    for s in sets:
        if v1 in s and v2 in s:
            print((1))
            break
        elif v1 in s or v2 in s:
            print((0))
            break


for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        unite(S, x, y)
    else:
        same(S, 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)

-S = set(frozenset([i]) for i in range(n)) -def unite(sets, v1, v2): -    s1 = None -    s2 = None -    for s in sets: -        if v1 in s and v2 in s: +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: -        elif v1 in s: -            s1 = s -        elif v2 in s: -            s2 = s -        if s1 and s2: -            break -    sets.discard(s1) -    sets.discard(s2) -    s3 = s1.union(s2) -    sets.add(s3) +        # 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)) -def same(sets, v1, v2): -    for s in sets: -        if v1 in s and v2 in s: -            print((1)) -            break -        elif v1 in s or v2 in s: -            print((0)) -            break - - +S = DisjointSets(n) -        unite(S, x, y) +        S.union(x, y) -        same(S, x, y) +        S.isSameSet(x, y)