#include <stdio.h>

int parent[10000];

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

void unite(int x, int y){
    int x2 = root(x);
    int y2 = root(y);
    parent[x2] = y2;
}

int main(void){
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i=0; i<n; i++)
        parent[i] = i;
    while(q--){
        int cmd, x, y;
        scanf("%d%d%d", &cmd, &x, &y);
        if(cmd){
            puts(root(x) == root(y) ? "1" : "0");
        }else{
            unite(x, y);
        }
    }
}
