#include <stdio.h>

int main(void) {
  int i, j, k, n, q, c, x, y;
  scanf("%d%d", &n, &q);
  int u[n];
  for(i = 0; i < n; ++i) u[i] = i;
  for(i = 0; i < q; ++i) {
    scanf("%d%d%d", &c, &x, &y);
    if(c) {
      while(u[x] != x) x = u[x];
      while(u[y] != y) y = u[y];
      if(x == y) printf("1\n");
      else printf("0\n");
    } else {
      while(u[x] != x) x = u[x];
      while(u[y] != y) y = u[y];
      u[y] = x;
    }
  }
  return 0;
}
