#include <stdio.h>

#define MAX (10000 + 5)
int p[MAX];
int rank[MAX];

void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
}

void link(int x, int y) {
    if(rank[x] > rank[y]) {
        p[y] = x;
    } else {
        p[x] = y;
        if(rank[x] == rank[y]) {  
            rank[y]++;
        }
    }
}

int findSet(int x) {
    if(x != p[x]) 
        p[x] = findSet(p[x]);
    return p[x];
}

void myUnion(int x, int y) {
    link( findSet(x), findSet(y) );
}
    
int isSameSet(int x, int y) {
    return findSet(x) == findSet(y);
}
    
int main(void) {
	int i,n,q;
	int com,x,y;
	scanf("%d %d\n", &n, &q);
	for(i=0;i<n;i++) makeSet(i);
	
	for(i=0;i<q;i++) {
		scanf("%d %d %d\n", &com, &x, &y);
		if(com == 0) {
			/* 結合 */
			myUnion(x, y);
		} else {
			printf("%d\n", isSameSet(x, y));
		}
	}
	
	return 0;
}