#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 10000

int par[MAX_N + 1];
int rank[MAX_N + 1];

void
init_union_find(int n)
{
	int i;

	for (i = 0; i <= n; ++i)
	{
		par[i] = i;
		rank[i] = 0;
	}
}

int
find(int x)
{
	if (x == par[x])
		return x;
	else
		return par[x] = find(par[x]);
}

void
unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y)
		return;

	if (rank[x] < rank[y])
		par[x] = y;
	else
	{
		par[y] = x;
		if (rank[x] == rank[y])
			rank[x]++;
	}
}

bool
same(int x, int y)
{
	return find(x) == find(y);
}

int
main(int argc, char** argv)
{
	int n, q;
	int c, x, y;

	scanf("%d %d", &n, &q);
	init_union_find(n);
	while (q--)
	{
		scanf("%d %d %d", &c, &x, &y);
		if (c == 0)
			unite(x, y);
		else
			printf("%d\n", same(x, y) ? 1 : 0);
	}

	return 0;
}