object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    val n = in.next.head
    val a = (0 to n-1).toArray
    def find(m: Int): Int = if(a(m) == m) m else {a(m) = find(a(m)); a(m)}
 
    def unite(x: Int, y: Int) = {
        val _x = find(x)
        val _y = find(y)
        if(_x != _y) a(_x) = _y
    }
 
    in.foreach(_ match {
        case Array(0, x, y) => unite(x, y)
        case Array(1, x, y) => println(if (find(x) == find(y)) 1 else 0)
    })
}