fun list() = readLine()!!.split(" ").map {it.toInt()}

class UF(size:Int) {
	private val a = IntArray(size) {-1}

	fun root(t:Int):Int = if(a[t]<0) t else root(a[t]).also {a[t] = it}

	fun isConnected(a:Int,b:Int) = root(a)==root(b)
	fun groupSize(t:Int) = -a[root(t)]

	fun connect(p:Int,q:Int):Boolean {
		val r = root(p)
		val s = root(q)
		if(r==s) return false
		if(a[r]>a[s]) {
			a[s] += a[r]
			a[r] = s
		} else {
			a[r] += a[s]
			a[s] = r
		}
		return true
	}
}

fun main() {
	val (n,q) = list()
	val uf = UF(n)

	for(i in 1..q) {
		val (t,u,v) = list()
		if(t==0)
			uf.connect(u,v)
		else
			println(if(uf.isConnected(u,v)) 1 else 0)
	}
}
