import java.util.*

fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

class UnionFind(size: Int) {
    private val par: IntArray = IntArray(size) { -1 }
    private val rank = IntArray(size) { 0 }

    private fun root(x: Int): Int =
        if (par[x] < 0) {
            x
        } else {
            par[x] = root(par[x])
            par[x]
        }

    fun count(x: Int): Int = -par[root(x)]

    fun isSame(x: Int, y: Int) = root(x) == root(y)

    fun unite(x: Int, y: Int) {
        val rootOfX = root(x)
        val rootOfY = root(y)
        if (rootOfX == rootOfY) return
        if (rank[rootOfX] < rank[rootOfY]) {
            par[rootOfY] += par[rootOfX]
            par[rootOfX] = rootOfY
        } else {
            par[rootOfX] += par[rootOfY]
            par[rootOfY] = rootOfX
        }
        if (rank[rootOfX] == rank[rootOfY]) rank[x]++
    }
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val Q = sc.next().toInt()
        val uf = UnionFind(N)
        repeat(Q) {
            val t = sc.next().toInt()
            val u = sc.next().toInt()
            val v = sc.next().toInt()
            if (t == 0) {
                uf.unite(u, v)
            } else {
                pw.println(if (uf.isSame(u, v)) 1 else 0)
            }
        }
    }
}
