#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define SIZE 10000
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int parent[SIZE];
int depth[SIZE];

int find(int x) {
    if (parent[x] == x)
        return x;
    return parent[x] = find(parent[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (depth[x] < depth[y]) {
        int tmp = x;
        x = y;
        y = tmp;
    }
    // depth[x] > depth[y]
    parent[y] = x;
    depth[x] = MAX(depth[x], depth[y] + 1);
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main (void)
{
    int i;
    int n, q;
    scanf("%d %d", &n, &q);
    for (i = 0; i < n; i++) {
        parent[i] = i;
    }
    int com, x, y;
    for (i = 0; i < q; i++) {
        scanf("%d %d %d", &com, &x, &y);
        if (com == 0) unite(x, y);
        else
            printf("%d\n", same(x, y)? 1 : 0);
    }
    return 0;
}
