#include <stdio.h>
int ELEMENTS[10000] = {0};
int RANK[10000] = {0};

void makeSet(int n) {
	int i;
	for (i = 0; i < n; ++i) {
		ELEMENTS[i] = i;
	}
}


void link(int x, int y) {
	if (RANK[x] > RANK[y]) {
		ELEMENTS[y] = x;
	} else {
		ELEMENTS[x] = y;
		if (RANK[x] == RANK[y]) {
			RANK[y]++;
		}
	}
	return;
}

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

//void union(int x, int y) {
//	link( findSet(x), findSet(y));
//}

void union2(int x, int y) {
	link(findSet(x), findSet(y));
	return;
}

int isSameSet(int x, int y) {
	return findSet(x) == findSet(y);
}


int main() {
	int n, q;
	int i;
	int com, x, y;
	scanf("%d %d", &n, &q);
	makeSet(n);
	
	for (i = 0; i < q; ++i) {
		scanf("%d %d %d", &com, &x, &y);
		if (com == 0) {
			union2(x,y);
		} else {
//			printf("%d %d\n", x, y);
			if(isSameSet(x, y)) {
				printf("1\n");
			} else {
				printf("0\n");
			}
 		}
	}
}