#include <stdio.h>

typedef struct {
	int parent, rank;
} Node;

Node node[10000];

void init(int n) {
	int i;
	for (i = 0; i < n; i++) {
		node[i].parent = i;
		node[i].rank = 0;
	}
}

int find(int x) {
	return node[x].parent != x ? node[x].parent = find(node[x].parent) : x;
}

void unite(int x, int y) {
	int xr = find(x), yr = find(y);

	if (node[xr].rank < node[yr].rank)
		node[xr].parent = yr;
	else {
		node[yr].parent = xr;
		if (node[xr].rank == node[yr].rank)
			node[xr].rank++;
	}
}

int main(void) {
	int n, q;

	scanf("%d %d", &n, &q);

	init(n);
	while (q--) {
		int com, x, y;

		scanf("%d %d %d", &com, &x, &y);

		switch (com) {
			case 0:
				unite(x, y);
				break;
			case 1:
				printf("%d\n", find(x) == find(y));
				break;
		}
	}

	return 0;
}