#include <iostream>
#define MAX 100001

using namespace std;

int par[MAX],rank[MAX],n,m;

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

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

void unite(int x,int y){
  x = find(x); y = find(y);
  if(x == y) return;
  
  if(rank[x] < rank[y]){
    par[x] = y;
  } else {
    par[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}

int main(void){
  int com,x,y;
  init();
  cin >> n >> m;
  for(int i = 0 ; i < m ; i++){
    cin >> com >> x >> y;
    if(com){
      same(x,y);
      if(par[x] == par[y]) cout << '1' << endl;
      else cout << '0' << endl;
    }
    else unite(x,y);
  }
  return 0;
}