import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

class UnionFind {
    int[] parent;
    this(int N) {
        parent = new int[N];
        parent[] = -1;
    }
    int root(int x) {
        if (parent[x] == -1) return x;
        return parent[x] = root(parent[x]);
    }
    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        parent[y] = x;
    }
    bool query(int x, int y) {
        return root(x) == root(y);
    }
}

void main() {
    int N, Q; scanf("%d %d\n", &N, &Q);
    auto uf = new UnionFind(N);
    foreach (i; 0 .. Q) {
        int t, x, y; scanf("%d %d %d\n", &t, &x, &y);
        if (t == 0) {
            uf.merge(x, y);
        } else {
            writeln(cast(int)uf.query(x, y));
        }
    }
}