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 ds = new int[][](n, 1);
    auto n2s = iota(n).array;

    foreach(i ; 0 .. n){
        ds[i][0] = i;
    }

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

        if(c == 0){
            merge(ds, n2s, x, y);
        } else{
            writeln(n2s[x] == n2s[y] ? 1 : 0);
        }
    }

    writefln("%(%s\n%)", ds);
}

void merge(int[][] ds, int[] n2s, int x, int y){
    auto u = n2s[x];
    auto v = n2s[y];

    if(u == v) return;

    if(u > v) swap(u, v);

    ds[v].length += ds[u].length;
    ds[v][$ - ds[u].length .. $] = ds[u];
    foreach(z ; ds[u]){
        n2s[z] = v;
    }
    delete ds[u];
}