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

void main(){
    auto rd = readln.split.to!(int[]);
    auto n = rd[0], q = rd[1];
    auto uf = new UnionFind(n);

    foreach(lp ; 0 .. q){
        rd = readln.split.to!(int[]);
        auto c = rd[0], x = rd[1], y = rd[2];

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

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

public:
    this(int N){
        ds = iota(N).array;
        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 is_same(int x, int y){
        return find_root(x) == find_root(y);
    }

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

        if(rank[u] < rank[v]){
            p[u] = v;
        } else{
            p[v] = u;

            if(rank[u] == rank[v]) ++rank[u];
        }
    }
}