#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,q;
	int m,a,b,x,y;
	int par[10000],ran[10000];
	int i;
	cin>>n>>q;
	for(i=0;i<n;i++)	par[i]=i,ran[i]=0;
	for(i=0;i<q;i++){
		cin>>m>>a>>b;
		x=a;	y=b;
		while(x!=par[x])	x=par[x];
		while(y!=par[y])	y=par[y];
		if(m==0){
			if(x!=y){
				if		(ran[x]>ran[y])	par[y]=x;
				else if	(ran[x]<ran[y])	par[x]=y;
				else					par[y]=x,ran[x]++;
			}
		}
		else{
			if(x==y)	cout<<1<<endl;
			else		cout<<0<<endl;
		}
	}
	return 0;
}
			
