#include<stdio.h>
#include<stdlib.h>
#define MAX 10001
#define QMAX 100000

typedef struct cell{
 int num;
 struct cell *parent;
}cell;



void merge(int x,int y,int rank[],cell S[]){
if(x!=y){
if(rank[x]>rank[y]){S[y].parent=&S[x];}
else{S[y].parent=&S[x];
     if(rank[x]==rank[y]){rank[x]++;}
         }
}






return;
}




int findSet(cell S[],int x){
cell *p=S[x].parent;

if(p==NULL){return x;}
else{
 while(p->parent!=NULL){
 p=p->parent;
 }
 return p->num;
}

}








int main(){
int n,i,com,x,y,q;
cell S[MAX];
int rank[MAX]={0};
int C[QMAX];

scanf("%d %d",&n,&q);

for(i=0;i<q;i++)C[i]=-1;


for(i=0;i<n;i++){
 S[i].num=i;
 S[i].parent=NULL;
}

for(i=0;i<q;i++){
 scanf("%d",&com);
 scanf("%d %d",&x,&y);

 switch(com){

  case 0:x=findSet(S,x);
         y=findSet(S,y);
         merge(x,y,rank,S);
         break;

  case 1:x=findSet(S,x);
         y=findSet(S,y);
         if(x==y){C[i]=1;}
         else{C[i]=0;}
         break;
 }


}/*for終わり*/


for(i=0;i<q;i++){
 if(C[i]!=-1){
  printf("%d\n",C[i]);
 }
}

return 0;
}
