// AOJ DSL_1 A Set - Disjoint Set: Union Find Tree
// 2017.10.31 bal4u@uu

#include <stdio.h>

#define MAX 10002
/* UNION-FIND library */
int p[MAX], rank[MAX];
void make_set(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] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

int main()
{
	int n, q, i;
	int cmd, x, y;

	scanf("%d%d", &n, &q);
	for (i = 1; i <= n; i++) make_set(i);
	for (i = 0; i < q; i++) {
		scanf("%d%d%d", &cmd, &x, &y);
		if (cmd == 0) union_set(x, y);
		else printf("%d\n", find_set(x) == find_set(y));
	}
	return 0;
}