# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10000)



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



tree = [[-1, 1]  for _ in range(N)] # [next, rank]



def find(i):

    if tree[i][0] == -1:

        group = i

    else:

        group = find(tree[i][0])    

    return group



def unite(x, y):

    px = find(x)

    py = find(y)

    

    if tree[px][1] == tree[py][1]: # rank is same

        tree[py][0] = px

        tree[px][1] += 1

    else:

        if tree[px][1] < tree[py][1]:

            px, py = py, px

        tree[py][0] = px



for _ in range(Q):

    com, x, y = tuple(map(int, input().split()))

    if com: # same

        print((int(find(x) == find(y))))

    else: # unite

        if not int(find(x) == find(y)):

            unite(x, y)
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10000)

 

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

 

tree = [[-1, 1]  for _ in range(N)] # [next, rank]

 

def find(i):

    if tree[i][0] == -1:

        group = i

    else:

        group = find(tree[i][0]) 

        tree[i][0] = group

    return group

 

def unite(x, y):

    px = find(x)

    py = find(y)

     

    if tree[px][1] == tree[py][1]: # rank is same

        tree[py][0] = px

        tree[px][1] += 1

    else:

        if tree[px][1] < tree[py][1]:

            px, py = py, px

        tree[py][0] = px

 

for _ in range(Q):

    com, x, y = tuple(map(int, input().split()))

    if com: # same

        print((int(find(x) == find(y))))

    else: # unite

        if not int(find(x) == find(y)):

            unite(x, y)

# -*- coding: utf-8 -*-
import sys

sys.setrecursionlimit(10000)
N, Q = tuple(map(int, input().split()))
tree = [[-1, 1] for _ in range(N)]  # [next, rank]


def find(i):
    if tree[i][0] == -1:
        group = i
    else:
        group = find(tree[i][0])
    return group


def unite(x, y):
    px = find(x)
    py = find(y)
    if tree[px][1] == tree[py][1]:  # rank is same
        tree[py][0] = px
        tree[px][1] += 1
    else:
        if tree[px][1] < tree[py][1]:
            px, py = py, px
        tree[py][0] = px


for _ in range(Q):
    com, x, y = tuple(map(int, input().split()))
    if com:  # same
        print((int(find(x) == find(y))))
    else:  # unite
        if not int(find(x) == find(y)):
            unite(x, y)

# -*- coding: utf-8 -*-
import sys

sys.setrecursionlimit(10000)
N, Q = tuple(map(int, input().split()))
tree = [[-1, 1] for _ in range(N)]  # [next, rank]


def find(i):
    if tree[i][0] == -1:
        group = i
    else:
        group = find(tree[i][0])
        tree[i][0] = group
    return group


def unite(x, y):
    px = find(x)
    py = find(y)
    if tree[px][1] == tree[py][1]:  # rank is same
        tree[py][0] = px
        tree[px][1] += 1
    else:
        if tree[px][1] < tree[py][1]:
            px, py = py, px
        tree[py][0] = px


for _ in range(Q):
    com, x, y = tuple(map(int, input().split()))
    if com:  # same
        print((int(find(x) == find(y))))
    else:  # unite
        if not int(find(x) == find(y)):
            unite(x, y)

+        tree[i][0] = group