#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


/*
 * ????????????????????\??????????£??????\???????????????
 * ????????§??????max??????????§?????????¨??????????£?????????????????????????????????£???????????????????????\??§??¨?????????????????????
 */
#define ELEMENT_NUM 10000

typedef struct UF{
    int parent;
}UF;

UF uf[ELEMENT_NUM + 1];


void initialize(int num){
    int i ;
    
    for (i=1; i <= num; i++) {
        uf[i].parent = i;
    }
}

int find(int a){

    if (a == uf[a].parent) {
        return a;
    }
    
    return uf[a].parent = find(uf[a].parent);
}

int isSame(int a, int b){
    
    if (find(a) == find(b)) {
        return 1;
    }
    else{
        return 0;
    }
}

void unite(int a, int b){
   a = find(a);
   b = find(b);
    
    if (a == b) {
        return;
    }
    
    uf[b].parent = a;
    
}


int main( ){
    
    int i, n, q, op, a, b;
    
    scanf("%d", &n);
    
    initialize(n);
    
    scanf("%d", &q);
    
    for (i=1; i<=q; i++){
        scanf("%d %d %d", &op, &a, &b);
        
        if (op == 0) {
            unite(a, b);
        }
        else{
            printf("%d\n", isSame(a, b));
        }
    }
    
    return 0;
}