class UnionFind(val size : Int) {
    val data = Array.fill(size)(-1)
    def find(x : Int) : Int = {
        if (data(x) < 0) x
        else {
          data(x) = find(data(x))
          data(x)
        }
    }
    def unite(x : Int, y : Int) = {
        val xPar = find(x)
        val yPar = find(y)
        if (xPar != yPar) {
            val (to, from) = if (data(yPar) > data(xPar)) (yPar, xPar)
                             else (xPar, yPar)
            data(to) += data(from)
            data(from) = to
        }
    }
    def same(x : Int, y : Int) = find(x) == find(y)
    override def toString() = data.toList.toString
}

object Main {
    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n, q = sc.nextInt
        val s = new UnionFind(n)
        for (i <- 1 to q) {
            val com, x, y = sc.nextInt
            (com : @unchecked) match {
                case 0 => s.unite(x, y)
                case 1 => {
                    if (s.same(x, y)) println(1) else println(0)
                }
            }
        }
    }
}
