#include <stdio.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)

//union-find
#define UFLIMIT (1<<17)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int ufroot(int x){return unicnt[x]<=0?-(unicnt[x]=-ufroot(-unicnt[x])):x;}
int ufsame(int x,int y){return ufroot(x)==ufroot(y);}
void uni(int x,int y){if((x=ufroot(x))==(y=ufroot(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT


int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	ufinit(n);
	while(q--){
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(t)printf("%d\n",ufsame(x,y));
		else uni(x,y);
	}
}
