import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    auto nq = readints();
    int n = nq[0], q = nq[1];

    auto uf = new UnionFind(n);
    for (int i = 0; i < q; i++) {
        auto xs = readints();
        int com = xs[0], x = xs[1], y = xs[2];
        switch (com) {
        case 0:
            uf.unite(x, y);
            break;

        case 1:
            writeln(uf.isSame(x, y) ? 1 : 0);
            break;
        default:
        }
    }
}

class UnionFind {
    private int[] _data;

    this(int n) {
        _data = new int[](n + 1);
        _data[] = -1;
    }

    int root(int a) {
        if (_data[a] < 0)
            return a;
        return _data[a] = root(_data[a]);
    }

    bool unite(int a, int b) {
        int rootA = root(a);
        int rootB = root(b);
        if (rootA == rootB)
            return false;
        _data[rootA] += _data[rootB];
        _data[rootB] = rootA;
        return true;
    }

    bool isSame(int a, int b) {
        return root(a) == root(b);
    }

    int size(int a) {
        return -_data[root(a)];
    }
}