#include<iostream>

using namespace std;
#define MAX_N 10000

int par[MAX_N];
void init(int n) {
  for (int i = 0; i < n; i++) par[i] = i;
}

int Find(int x) {
  if(par[x] == x) {
    return x;
  } else {
    return par[x] = Find(par[x]);
  }
}

bool Same(int x, int y) {
  return Find(x) == Find(y);
}

void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  if (x == y) return;

  par[x] = y;
  return;
}

int main() {
  int n, q, com, x, y;
  cin >> n >> q;
  init(n);
  while(q-- > 0) {
    cin >> com >> x >> y;
    if(com == 0) {
      Union(x, y);
    } else {
      cout << Same(x, y) << endl;
    }
  }
  return 0;
}

