import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format, std.numeric;

class UnionFind
{
private:
    long[] xs;
public:
    this(ulong size)
    {
        xs = new long[](size);
        fill(xs, -1);
    }

    long find(long i)
    {
        if (xs[i] == -1)
        {
            return i;
        }
        return find(xs[i]);
    }

    void unite(long x, long y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
        {
            return;
        }
        xs[x] = y;
    }

}

void main(string[] args)
{

    long n, q, com, x, y;

    readf("%d %d\n", &n, &q);
    auto uf = new UnionFind(n);

    foreach (_; 0 .. q)
    {
        readf("%d %d %d\n", &com, &x, &y);
        if (com == 0)
        {
            uf.unite(x, y);
        }
        if (com == 1)
        {
            if (uf.find(x) == uf.find(y))
            {
                writeln("1");
            }
            else
            {
                writeln("0");
            }
        }
    }
}

