#include<iostream>
using namespace std;
const int maxp=10005;
int n,q,Tree[maxp];

int GetP(int s) {
	if(Tree[s]==s) return s;
	else return Tree[s]=GetP(Tree[s]);
}

void Merge(int x,int y) {
	int px=GetP(x),py=GetP(y);
	if(px!=py) Tree[py]=px;
}

bool Check(int x,int y) {
	int px=GetP(x),py=GetP(y);
	if(px==py) return true;
	else return false;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin.tie(NULL);
	cin>>n>>q;
	for(int i=0; i<n; i++)
		Tree[i]=i;
	int judge,x,y;
	while(q--) {
		cin>>judge>>x>>y;
		if(judge) {
			if(Check(x,y)) cout<<"1"<<endl;
			else cout<<"0"<<endl;
		} else Merge(x,y);
	}
	return 0;
}
