import { stringify } from "querystring";

let input = require("fs").readFileSync("/dev/stdin", "utf8");
let cin = input.split(/ |\n/), cid = 0;
function next() { return +cin[cid++]; }
//input from catoonさん

function buffer(){
    // if (console._LOG_BUFFER) return;
// console._LOG_BUFFER = true;

var util = require('util');

var cache = {};

// make sure to flush at exit
process.on('exit', flush);

// export the flush and patch functions
module.exports = patch;
module.exports.flush = flush;

// save the original functions, and make a buffer for each
['warn', 'log', 'error', 'info'].forEach(function(name) {
  cache[name] = {
    func: console[name].bind(console),
    size: 0,
    buf: []
  };
});

// patch when required
patch();

/**
 * Patch the console.* commands with the given
 * limit (default 8k)
 */
function patch(limit?, pre?) {
  limit = limit || 8192; // 8kb

  // overwrite the console.* functions to buffer
  Object.keys(cache).forEach(function(name) {
    console[name] = function() {
      // format the input
      var s = util.format.apply(this, arguments);
      if (typeof pre === 'string') s = pre + s;
      else if (typeof pre === 'function') s = pre() + s;

      // calculate the new length
      var len = Buffer.byteLength(s);
      cache[name].size += len;

      // push the data, and flush if > limit
      cache[name].buf.push(s);
      if (cache[name].size > limit) flush();
    };
  });
}

/**
 * Flush all the caches by calling the original function forEach
 */
function flush() {
  // flush all caches
  Object.keys(cache).forEach(function(name) {
    // dump the buffer if present
    if (cache[name].size)
      cache[name].func(cache[name].buf.join('\n'));

    // clear the buffer
    cache[name].buf.length = 0;
    cache[name].size = 0;
  });
}
}
buffer();

class UnionFind {
    p: number[];
    sizes: number[];
    tmpsize: number;
    constructor(n: number) {
        this.p = Array(n);
        this.sizes = Array(n).fill(1);
        for (let i = 0; i < n; i++) {
            this.p[i] = i;
        }
        this.tmpsize = n;
    }
    find(x: number) {
        if (this.p[x] === x) {
            return x;
        } else {
            let tmp = this.find(this.p[x]);
            return tmp;
        }
    }
    unite(x: number, y: number) {
        let findx = this.find(x);
        let findy = this.find(y);
        if (findx === findy) return;

        let [large, small] = this.sizes[findx] >= this.sizes[findy] ? [findx, findy] : [findy, findx];

        this.p[small] = large;
        this.sizes[large] += this.sizes[small];
        this.tmpsize--;

    }
    is_same(x: number, y: number) {
        return this.find(x) === this.find(y);
    }
}
function main(){
    let n = next();
    let q = next();
    let uf = new UnionFind(n);
    let rick = [];
    while (q--) {
        let condition = next();
        let tmp = next();
        let tmp1 = next();
        if (condition === 0) {
            uf.unite(tmp, tmp1);
        }
        else {
            if (uf.is_same(tmp, tmp1)) {
                // console.log(1);
                rick.push(1);
            }
            else {
                rick.push(0);
            }

        }
    }
    let ricktmp=  rick.join("\n");
    // console.log(ricktmp);
    return ricktmp;
}
console.log(String(main()));


Measured memory_bytes: 85252