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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int root(int *u,int x){
  if(u[x]==x) return x;
  return u[x]=root(u,u[x]);
}

int same(int *u,int x,int y){
  return root(u,x)==root(u,y);
}

void unite(int *u,int x,int y){
  x=root(u,x);
  y=root(u,y);
  if(x==y) return;
  u[x]=y;
}

void run(void){
  int n,q;
  scanf("%d%d",&n,&q);
  int *u=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) u[i]=i;
  while(q--){
    int c,x,y;
    scanf("%d%d%d",&c,&x,&y);
    if(c==0){
      unite(u,x,y);
    } else {
      printf("%d\n",same(u,x,y));
    }
  }
}

int main(void){
  run();
  return 0;
}

