def find(u)
	if $f[u] == u
		return u
	end
	$f[u] = find($f[u])
	return $f[u]
end

def unite(a, b)
	a = find(a)
	b = find(b)
	if (a != b)
		$f[a] = b
	end
end

def same(a, b)
	a = find(a)
	b = find(b)
	if a == b
		return 1
	else
		return 0
	end
end

n, m = gets.split
n = n.to_i
m = m.to_i
$f = Array.new
(0..n).each do |i|
	$f.push(i)
end
(1..m).each do
	k, a, b, = gets.split
	k = k.to_i
	a = a.to_i
	b = b.to_i
	if (k == 0)
		unite(a, b)
	else
		p same(a, b)
	end
end