#include <stdio.h>
#include <stdlib.h>


int *BOX;


void Init(int n)
{
	int i;

	for(i = 0; i < n; i++)
		BOX[i] = i;
}


int Find(int x)
{
	if(BOX[x] == x)
		return x;
	else{
		BOX[x] = Find(BOX[x]);
		return BOX[x];
	}
}


int Same(int x, int y)
{
	if(Find(x) == Find(y))
		return 1;

	return 0;
}


void Unite(int x, int y)
{
	x = Find(x);
	y = Find(y);

	if(x == y)
		return;

	BOX[x] = y;
}


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

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

	BOX = (int *)malloc(sizeof(int) * n);

	Init(n);

	for(i = 0; i < q; i++){
		scanf("%d", &com);

		if(com){
		// Same
			scanf("%d %d", &x, &y);
			if(Same(x, y))
				printf("1\n");
			else
				printf("0\n");
		}else{
		// Unite
			scanf("%d %d", &x, &y);
			Unite(x, y);
		}
	}

	return 0;
}
