n, q = map(int, input().split())

forest = [-1]*n





def get_root(x: int) -> int:

    if forest[x] < 0:

        return x

    else:

        forest[x] = get_root(forest[x])

        return forest[x]





def unite(x: int, y: int) -> None:

    root_x, root_y = get_root(x), get_root(y)

    if root_x != root_y:

        bigroot, smallroot = \

            (root_x, root_y) if forest[root_x] < forest[root_y]\

            else (root_y, root_x)

        forest[bigroot] += forest[smallroot]

        forest[smallroot] = bigroot



for _ in [None]*q:

    c, x, y = map(int, input().split())

    if c == 0:

        unite(x, y)

    else:

        print(1 if get_root(x) == get_root(y) else 0)

def get_root(nodes, x: int) -> int:

    if nodes[x] < 0:

        return x

    else:

        nodes[x] = get_root(nodes, nodes[x])

        return nodes[x]





def unite(nodes, x: int, y: int) -> None:

    root_x, root_y = get_root(nodes, x), get_root(nodes, y)

    if root_x != root_y:

        bigroot, smallroot = \

            (root_x, root_y) if nodes[root_x] < nodes[root_y] else (root_y, root_x)

        nodes[bigroot] += nodes[smallroot]

        nodes[smallroot] = bigroot





if __name__ == "__main__":

    import sys

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

    nodes = [-1]*N

    result = []

    append = result.append



    for p, a, b in (map(int, l.split()) for l in sys.stdin):

        if not p:

            unite(nodes, a, b)

        else:

            append(1 if get_root(nodes, a) == get_root(nodes, b) else 0)



    print(*result, sep="\n")

n, q = map(int, input().split())
forest = [-1] * n


def get_root(x: int) -> int:
    if forest[x] < 0:
        return x
    else:
        forest[x] = get_root(forest[x])
        return forest[x]


def unite(x: int, y: int) -> None:
    root_x, root_y = get_root(x), get_root(y)
    if root_x != root_y:
        bigroot, smallroot = (
            (root_x, root_y) if forest[root_x] < forest[root_y] else (root_y, root_x)
        )
        forest[bigroot] += forest[smallroot]
        forest[smallroot] = bigroot


for _ in [None] * q:
    c, x, y = map(int, input().split())
    if c == 0:
        unite(x, y)
    else:
        print(1 if get_root(x) == get_root(y) else 0)

def get_root(nodes, x: int) -> int:
    if nodes[x] < 0:
        return x
    else:
        nodes[x] = get_root(nodes, nodes[x])
        return nodes[x]


def unite(nodes, x: int, y: int) -> None:
    root_x, root_y = get_root(nodes, x), get_root(nodes, y)
    if root_x != root_y:
        bigroot, smallroot = (
            (root_x, root_y) if nodes[root_x] < nodes[root_y] else (root_y, root_x)
        )
        nodes[bigroot] += nodes[smallroot]
        nodes[smallroot] = bigroot


if __name__ == "__main__":
    import sys

    N, Q = map(int, input().split())
    nodes = [-1] * N
    result = []
    append = result.append
    for p, a, b in (map(int, l.split()) for l in sys.stdin):
        if not p:
            unite(nodes, a, b)
        else:
            append(1 if get_root(nodes, a) == get_root(nodes, b) else 0)
    print(*result, sep="\n")

-n, q = map(int, input().split()) -forest = [-1] * n +def get_root(nodes, x: int) -> int: +    if nodes[x] < 0: +        return x +    else: +        nodes[x] = get_root(nodes, nodes[x]) +        return nodes[x] -def get_root(x: int) -> int: -    if forest[x] < 0: -        return x -    else: -        forest[x] = get_root(forest[x]) -        return forest[x] +def unite(nodes, x: int, y: int) -> None: +    root_x, root_y = get_root(nodes, x), get_root(nodes, y) +    if root_x != root_y: +        bigroot, smallroot = ( +            (root_x, root_y) if nodes[root_x] < nodes[root_y] else (root_y, root_x) +        ) +        nodes[bigroot] += nodes[smallroot] +        nodes[smallroot] = bigroot -def unite(x: int, y: int) -> None: -    root_x, root_y = get_root(x), get_root(y) -    if root_x != root_y: -        bigroot, smallroot = ( -            (root_x, root_y) if forest[root_x] < forest[root_y] else (root_y, root_x) -        ) -        forest[bigroot] += forest[smallroot] -        forest[smallroot] = bigroot +if __name__ == "__main__": +    import sys - -for _ in [None] * q: -    c, x, y = map(int, input().split()) -    if c == 0: -        unite(x, y) -    else: -        print(1 if get_root(x) == get_root(y) else 0) +    N, Q = map(int, input().split()) +    nodes = [-1] * N +    result = [] +    append = result.append +    for p, a, b in (map(int, l.split()) for l in sys.stdin): +        if not p: +            unite(nodes, a, b) +        else: +            append(1 if get_root(nodes, a) == get_root(nodes, b) else 0) +    print(*result, sep="\n")