function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
	let N = parseInt(input[0][0], 10);
	let Q = parseInt(input[0][1], 10);
	let uf = new UnionFind(N);
	let line;
	let v_ans = [];
	for (let i = 0; i < Q; i++){
		line = input[i + 1].map(e => parseInt(e, 10));
		if (line[0] === 0) uf.union(line[1], line[2]);
		else (uf.find(line[1]) === uf.find(line[2])) ? v_ans.push(1) : v_ans.push(0);
	}
	console.log(v_ans.join("\n"));
}

function UnionFind (n) {
	this.parents = [];
	for (let i = 0; i < n; i++) {
		this.parents.push(-1);
	}
}

UnionFind.prototype.find = function (x) {
	if (this.parents[x] < 0) return x;
	return this.parents[x] = this.find(this.parents[x]);	
}

UnionFind.prototype.union = function (x, y) {
	x = this.find(x);
	y = this.find(y);
	if (x === y) return;
	if (this.parents[x] > this.parents[y]) [x, y] = [y, x];
	
	this.parents[x] += this.parents[y];
	this.parents[y] = x;
}

UnionFind.prototype.size = function (x) {
	x = this.find(x);
	while (x >= 0) {
		x = this.parents[x];
	}
	return x * -1;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

