#include <cstdio>
#include <cstring>

class kin{
public:
	inline void open(void);
	inline void close(void);
	inline void read(void);
	inline kin &operator >>(char &);
	inline kin &operator >>(int &);
	inline kin &operator >>(long long &);
	inline kin &operator >>(double &);
	inline kin &operator >>(long double &);
	inline kin &operator >>(char *);
	char *buf;
	int siz;
	int idx;
}in;

class kout{
public:
	inline void open(void);
	inline void close(void);
	inline void write(void);
	inline kout &operator <<(char);
	inline kout &operator <<(int);
	inline kout &operator <<(long long);
	inline kout &operator <<(double);
	inline kout &operator <<(long double);
	inline kout &operator <<(char *);
	char *buf;
	int idx;
}out;

int *par;

inline int root(int node){
	if(par[node]<0) return node;
	return par[node]=root(par[node]);
}

int main(int argc,char **argv){
	in.open();
	out.open();
	in.read();
	int n,q;
	in>>n>>q;
	par=new int[n];
	for(int i=0;i<n;++i) par[i]=-1;
	int t,u,v;
	for(int i=0;i<q;++i){
		in>>t>>u>>v;
		u=root(u);
		v=root(v);
		if(t) out<<(u==v?1:0)<<'\n';
		else if(u!=v){
			if(par[u]>par[v]){
				par[v]+=par[u];
				par[u]=v;
			}
			else{
				par[u]+=par[v];
				par[v]=u;
			}
		}
	}
	delete[] par;
	out.write();
	in.close();
	out.close();
	return 0;
}

inline void kin::open(void){
	buf=new char[512];
	siz=0;
	idx=0;
	return;
}
inline void kin::close(void){
	delete[] buf;
	buf=nullptr;
	siz=0;
	idx=0;
	return;
}
inline void kin::read(void){
	siz=(int)std::fread((void *)buf,(std::size_t)1,(std::size_t)512,stdin);
	if(!siz) buf[0]='\x00';
	idx=0;
	return;
}
inline kin &kin::operator >>(char &obj){
	while(buf[idx]<'\x21'||buf[idx]>='\x7F'){
		if(!siz){
			obj='\x00';
			return *this;
		}
		if(++idx==siz) read();
	}
	obj=buf[idx];
	if(++idx==siz) read();
	return *this;
}
inline kin &kin::operator >>(int &obj){/*
	while(buf[idx]!='\x2D'&&(buf[idx]<'\x30'||buf[idx]>='\x3A')){
		if(!siz){
			obj=0;
			return *this;
		}
		if(++idx==siz) read();
	}
	int sign=-1;
	if(buf[idx]=='\x2D'){
		sign=1;
		if(++idx==siz) read();
	}
	obj=0;
	while(buf[idx]>='\x30'&&buf[idx]<'\x3A'){
		obj=obj*10-(int)(buf[idx]-'\x30');
		if(++idx==siz) read();
	}
	obj*=sign;
	return *this;*/
	obj=0;
	while(buf[idx]>='\x30'){
		obj=obj*10+(int)(buf[idx]-'\x30');
		if(++idx==siz) read();
	}
	if(++idx==siz) read();
	return *this;
}
inline kin &kin::operator >>(long long &obj){
	while(buf[idx]!='\x2D'&&(buf[idx]<'\x30'||buf[idx]>='\x3A')){
		if(!siz){
			obj=0LL;
			return *this;
		}
		if(++idx==siz) read();
	}
	long long sign=-1LL;
	if(buf[idx]=='\x2D'){
		sign=1LL;
		if(++idx==siz) read();
	}
	obj=0LL;
	while(buf[idx]>='\x30'&&buf[idx]<'\x3A'){
		obj=obj*10LL-(long long)(buf[idx]-'\x30');
		if(++idx==siz) read();
	}
	obj*=sign;
	return *this;
}
inline kin &kin::operator >>(double &obj){
	while(buf[idx]!='\x2D'&&buf[idx]!='\x2E'&&(buf[idx]<'\x30'||buf[idx]>='\x3A')){
		if(!siz){
			obj=0.0;
			return *this;
		}
		if(++idx==siz) read();
	}
	double sign=-1.0;
	if(buf[idx]=='\x2D'){
		sign=1.0;
		if(++idx==siz) read();
	}
	obj=0.0;
	while(buf[idx]!='\x2E'&&buf[idx]>='\x30'&&buf[idx]<'\x3A'){
		obj=obj*10.0-(double)(buf[idx]-'\x30');
		if(++idx==siz) read();
	}
	if(buf[idx]=='\x2E'){
		double dig=1.0;
		if(++idx==siz) read();
		while(buf[idx]>='\x30'&&buf[idx]<'\x3A'){
			obj-=(double)(buf[idx]-'\x30')*(dig/=10.0);
			if(++idx==siz) read();
		}
	}
	obj*=sign;
	return *this;
}
inline kin &kin::operator >>(long double &obj){
	while(buf[idx]!='\x2D'&&buf[idx]!='\x2E'&&(buf[idx]<'\x30'||buf[idx]>='\x3A')){
		if(!siz){
			obj=0.0L;
			return *this;
		}
		if(++idx==siz) read();
	}
	long double sign=-1.0L;
	if(buf[idx]=='\x2D'){
		sign=1.0L;
		if(++idx==siz) read();
	}
	obj=0.0;
	while(buf[idx]!='\x2E'&&buf[idx]>='\x30'&&buf[idx]<'\x3A'){
		obj=obj*10.0L-(long double)(buf[idx]-'\x30');
		if(++idx==siz) read();
	}
	if(buf[idx]=='\x2E'){
		long double dig=1.0L;
		if(++idx==siz) read();
		while(buf[idx]>='\x30'&&buf[idx]<'\x3A'){
			obj-=(long double)(buf[idx]-'\x30')*(dig/=10.0L);
			if(++idx==siz) read();
		}
	}
	obj*=sign;
	return *this;
}
inline kin &kin::operator >>(char *str){
	while(buf[idx]<'\x21'||buf[idx]>='\x7F'){
		if(!siz){
			str[0]='\x00';
			return *this;
		}
		if(++idx==siz) read();
	}
	int k=0;
	while(buf[idx]>='\x21'&&buf[idx]<'\x7F'){
		str[k++]=buf[idx];
		if(++idx==siz) read();
	}
	str[k]='\x00';
	return *this;
}
inline void kout::open(void){
	buf=new char[512];
	idx=0;
	return;
}
inline void kout::close(void){
	delete[] buf;
	buf=nullptr;
	idx=0;
	return;
}
inline void kout::write(void){
	std::fwrite((void *)buf,(std::size_t)1,(std::size_t)idx,stdout);
	idx=0;
	return;
}
inline kout &kout::operator <<(char val){
	buf[idx]=val;
	if(++idx==512) write();
	return *this;
}

inline kout &kout::operator <<(int val){/*
	if(val<0){
		buf[idx]='\x2D';
		if(++idx==512) write();
	}
	else val*=-1;
	int dig=1;
	while(val/dig<=-10) dig*=10;
	int tmp;
	while(dig){
		buf[idx]=(char)-(tmp=val/dig)+'\x30';
		if(++idx==512) write();
		val-=tmp*dig;
		dig/=10;
	}
	return *this;*/
	buf[idx]=(char)val+'\x30';
	if(++idx==512) write();
	return *this;
}
inline kout &kout::operator <<(long long val){
	if(val<0LL){
		buf[idx]='\x2D';
		if(++idx==512) write();
	}
	else val*=-1LL;
	long long dig=1LL;
	while(val/dig<=-10LL) dig*=10LL;
	long long tmp;
	while(dig){
		buf[idx]=(char)-(tmp=val/dig)+'\x30';
		if(++idx==512) write();
		val-=tmp*dig;
		dig/=10LL;
	}
	return *this;
}
inline kout &kout::operator <<(double val){
	if(val<0.0){
		buf[idx]='\x2D';
		if(++idx==512) write();
	}
	else val*=-1.0;
	double dig=1.0;
	while(val/dig<=-10.0) dig*=10.0;
	double tmp;
	while(dig>=1.0){
		buf[idx]=(char)-(tmp=val/dig)+'\x30';
		if(++idx==512) write();
		val-=(double)(int)tmp*dig;
		dig/=10.0;
	}
	buf[idx]='\x2E';
	if(++idx==512) write();
	for(int i=0;i<12;++i){
		buf[idx]=(char)-(tmp=val/dig)+'\x30';
		if(++idx==512) write();
		val-=(double)(int)tmp*dig;
		dig/=10.0;
	}
	return *this;
}
inline kout &kout::operator <<(long double val){
	if(val<0.0L){
		buf[idx]='\x2D';
		if(++idx==512) write();
	}
	else val*=-1.0L;
	long double dig=1.0L;
	while(val/dig<=-10.0L) dig*=10.0L;
	long double tmp;
	while(dig>=1.0L){
		buf[idx]=(char)-(tmp=val/dig)+'\x30';
		if(++idx==512) write();
		val-=(long double)(int)tmp*dig;
		dig/=10.0L;
	}
	buf[idx]='\x2E';
	if(++idx==512) write();
	for(int i=0;i<16;++i){
		buf[idx]=(char)-(tmp=val/dig)+'\x30';
		if(++idx==512) write();
		val-=(long double)(int)tmp*dig;
		dig/=10.0L;
	}
	return *this;
}
inline kout &kout::operator <<(char *str){
	int k=0;
	while(str[k]){
		buf[idx]=str[k++];
		if(++idx==512) write();
	}
	return *this;
}



Measured memory_bytes: 2664