#include<stdio.h>
#include<string.h>
#define MAX_ELEMENTS 10000
int root[MAX_ELEMENTS];
void init(){
  memset(root, -1, sizeof(root));
}

int find(int x){
  if(root[x] < 0){
    return x;
  }  
  return root[x] = find(root[x]);
}

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

int size(int x){
  return -root[find(x)];
}

int unite(int x, int y){
  int tmp;
  x = find(x);
  y = find(y);
  if(x == y){
    return 0;
  }
  if(root[y] < root[x]){
    tmp = x;
    x = y;
    y = tmp;
  }
  root[x] += root[y];
  root[y] = x;
  return 1;
}
 
int main(){
  int n, q, com, x, y;
  scanf("%d %d", &n, &q);
  init();
  for(int 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));
    }
  }
  return 0;
}