import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable int mod = 10^^9 + 7;

void main(){
    int n, q;
    readVars(n, q);

    auto uf = new UnionFind(n);

    int com, x, y;

    foreach(qi ; 0 .. q){
        readVars(com, x, y);

        if (com == 0) {
            uf.unite(x, y);
        }
        else {
            writeln(uf.same(x, y) ? 1 : 0);
        }
    }
}

class UnionFind {
private:
    int[] p;
    int[] rank;

public:
    this(int N){
        p = iota(N).array;
        rank = new int[](N);
    }

    int find_root(int x){
        if(x != p[x]){
            p[x] = find_root(p[x]);
        }

        return p[x];
    }

    bool same(int x, int y){
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y){
        x = find_root(x);
        y = find_root(y);

        if(x == y) return;

        if(rank[x] < rank[y]){
            p[x] = y;
        }
        else {
            p[y] = x;

            if(rank[x] == rank[y]) rank[x]++;
        }
    }
}


void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}