#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxx=10010;
int pre[maxx];

int find(int x){
	if(pre[x]!=x) x=find(pre[x]);
	return x;
}

int main (){
	for(int i=0;i<maxx;i++) pre[i]=i;
	int n,m;
	cin>>n>>m;
	int com,x,y;
	while(m--){
		cin>>com>>x>>y;
		if(com==0) pre[find(x)]=find(y);
		else if(find(x)==find(y)) puts("1");
		else puts("0");
	}
	return 0;
}
