#include <bits/stdc++.h>
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
using namespace std;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;

int parent[N], siz[N];

void make_set(int v) { parent[v] = v; }

int find_set(int v) {
  while (v != parent[v])
    v = parent[v];
  return v;
}

void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (siz[a] < siz[b])
      swap(a, b);
    parent[b] = a;
    siz[a] += siz[b];
  }
}

int32_t main() {
  fast;
  memset(siz, 0, sizeof siz);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    make_set(i);
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0)
      union_sets(u, v);
    else {
      if (find_set(u) == find_set(v))
        cout << 1 << endl;
      else
        cout << 0 << endl;
    }
  }
}

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int parent[N], siz[N];

void make_set(int v) { parent[v] = v; }

int find_set(int v) {
  while (v != parent[v])
    v = parent[v];
  return v;
}

void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (siz[a] < siz[b])
      swap(a, b);
    parent[b] = a;
    siz[a] += siz[b];
  }
}

int32_t main() {
  fast;
  memset(siz, 0, sizeof siz);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    make_set(i);
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0)
      union_sets(u, v);
    else {
      if (find_set(u) == find_set(v))
        cout << 1 << endl;
      else
        cout << 0 << endl;
    }
  }
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

class UnionFind {
private:
  vector<int> r;

public:
  UnionFind(int N) { r.assign(N, -1); }

  int root(int x) { return (r[x] < 0) ? x : root(r[x]); }

  bool connected(int x, int y) { return root(x) == root(y); }

  void merge(int x, int y) {
    x = root(x);
    y = root(y);

    if (r[x] < r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;
  UnionFind U{N};
  while (Q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (!t) {
      U.merge(u, v);
    } else {
      cout << U.connected(u, v) << endl;
    }
  }
  return 0;
}

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

class UnionFind {
public:
  UnionFind() : _n{0} {}
  UnionFind(int n) : _n{n}, pr(n, -1) {}

  int merge(int a, int b) {
    assert(0 <= a && a < _n);
    assert(0 <= b && b < _n);
    a = leader(a);
    b = leader(b);
    if (a == b)
      return a;
    if (-pr[a] < -pr[b])
      swap(a, b);
    pr[a] += pr[b];
    pr[b] = a;
    return a;
  }

  bool same(int a, int b) {
    assert(0 <= a && a < _n);
    assert(0 <= b && b < _n);
    return leader(a) == leader(b);
  }

  int leader(int a) {
    assert(0 <= a && a < _n);
    return (pr[a] < 0) ? a : (pr[a] = leader(pr[a]));
  }

private:
  int _n;
  vector<int> pr;
};

int main() {
  int N, Q;
  cin >> N >> Q;
  UnionFind U{N};
  while (Q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (!t) {
      U.merge(u, v);
    } else {
      cout << U.same(u, v) << endl;
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #pragma GCC target("arch=skylake-avx512")

#pragma region template

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr const ll dx[4] = {1, 0, -1, 0};
constexpr const ll dy[4] = {0, 1, 0, -1};
constexpr const ll MOD = 1e9 + 7;
constexpr const ll mod = 998244353;
constexpr const ll INF = 1LL << 60;
constexpr const ll inf = 1 << 30;
constexpr const char rt = '\\n';
constexpr const char sp = ' ';
#define rt(i, n) (i == (ll)(n)-1 ? rt : sp)
#define len(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ifn(x) if (not(x))
#define elif else if
#define elifn else ifn
#define fi first
#define se second
#define uniq(x) (sort(all(x)), (x).erase(unique(all(x)), (x).end()))
#define bis(x, y) ((ll)(lower_bound(all(x), y) - (x).begin()))

using graph = vector<vector<ll>>;
template <class T> using wgraph = vector<vector<pair<ll, T>>>;
bool __DIRECTED__ = true;
bool __ZERO_INDEXED__ = false;
istream &operator>>(istream &is, graph &g) {
  ll a, b;
  is >> a >> b;
  if (__ZERO_INDEXED__ == false)
    a--, b--;
  g[a].pb(b);
  if (__DIRECTED__ == false)
    g[b].pb(a);
  return is;
}
template <class T> istream &operator>>(istream &is, wgraph<T> &g) {
  ll a, b;
  T c;
  is >> a >> b >> c;
  if (__ZERO_INDEXED__ == false)
    a--, b--;
  g[a].pb({b, c});
  if (__DIRECTED__ == false)
    g[b].pb({a, c});
  return is;
}

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

// Debug
#define debug(...)                                                             \\
  {                                                                            \\
    cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                         \\
    for (auto &&__i : {__VA_ARGS__})                                           \\
      cerr << "[" << __i << "] ";                                              \\
    cerr << rt;                                                                \\
  }

#define dump(a, h, w)                                                          \\
  {                                                                            \\
    cerr << __LINE__ << ": " << #a << " = [" << rt;                            \\
    rep(__i, h) {                                                              \\
      rep(__j, w) {                                                            \\
        if (abs(a[__i][__j]) >= INF / 2 and a[__i][__j] <= -INF / 2)           \\
          cerr << '-';                                                         \\
        if (abs(a[__i][__j]) >= INF / 2)                                       \\
          cerr << "∞" << sp;                                                   \\
        else                                                                   \\
          cerr << a[__i][__j] << sp;                                           \\
      }                                                                        \\
      cerr << rt;                                                              \\
    }                                                                          \\
    cerr << "]" << rt;                                                         \\
  }

#define vdump(a, n)                                                            \\
  {                                                                            \\
    cerr << __LINE__ << ": " << #a << " = [";                                  \\
    rep(__i, n) {                                                              \\
      if (__i)                                                                 \\
        cerr << sp;                                                            \\
      if (abs(a[__i]) >= INF / 2 and a[__i] <= -INF / 2)                       \\
        cerr << '-';                                                           \\
      if (abs(a[__i]) >= INF / 2)                                              \\
        cerr << "∞" << sp;                                                     \\
      else                                                                     \\
        cerr << a[__i];                                                        \\
    }                                                                          \\
    cerr << "]" << rt;                                                         \\
  }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)

// Stream
#define fout(n) cout << fixed << setprecision(n)
struct io {
  io() { cin.tie(nullptr), ios::sync_with_stdio(false); }
} io;

// Speed
#pragma GCC target(                                                            \\
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast,unroll-loops")

// Math
inline constexpr ll gcd(const ll a, const ll b) {
  return b ? gcd(b, a % b) : a;
}
inline constexpr ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }

inline constexpr ll modulo(const ll n, const ll m = MOD) {
  ll k = n % m;
  return k + m * (k < 0);
}
inline constexpr ll chmod(ll &n, const ll m = MOD) {
  n %= m;
  return n += m * (n < 0);
}
inline constexpr ll mpow(ll a, ll n, const ll m = MOD) {
  ll r = 1;
  rep(i, 64) {
    if (n & (1LL << i))
      r *= a;
    chmod(r, m);
    a *= a;
    chmod(a, m);
  }
  return r;
}
inline ll inv(const ll n, const ll m = MOD) {
  ll a = n, b = m, x = 1, y = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    x -= t * y;
    swap(x, y);
  }
  return modulo(x, m);
}

#pragma endregion

struct link_cut_tree {
  struct node {
    node *pp, *lp, *rp;
    ll idx, data, val, sum, cnt;
    bool rev;
    node(ll i = 0, ll d = 0, ll v = 0)
        : pp(nullptr), lp(nullptr), rp(nullptr), idx(i), data(d), val(v),
          sum(d), cnt(1), rev(0) {}
    bool is_root() {
      return pp == nullptr or (pp->lp != this and pp->rp != this);
    }
  };
  void rotr(node *x) {
    node *q = x->pp, *r = q->pp;
    if (q->lp = x->rp; x->rp != nullptr)
      x->rp->pp = q;
    x->rp = q, q->pp = x;
    update(q), update(x);
    if (x->pp = r; r != nullptr) {
      if (r->lp == q)
        r->lp = x;
      if (r->rp == q)
        r->rp = x;
      update(r);
    }
  }
  void rotl(node *x) {
    node *q = x->pp, *r = q->pp;
    if (q->rp = x->lp; x->lp != nullptr)
      x->lp->pp = q;
    x->lp = q, q->pp = x;
    update(q), update(x);
    if (x->pp = r; r != nullptr) {
      if (r->lp == q)
        r->lp = x;
      if (r->rp == q)
        r->rp = x;
      update(r);
    }
  }
  void splay(node *x) {
    push(x);
    while (not x->is_root()) {
      node *q = x->pp;
      if (q->is_root()) {
        push(q), push(x);
        q->lp == x ? rotr(x) : rotl(x);
      } else {
        node *r = q->pp;
        push(r), push(q), push(x);
        if (r->lp == q) {
          q->lp == x ? rotr(q) : rotl(x), rotr(x);
        } else {
          q->rp == x ? rotl(q) : rotr(x), rotl(x);
        }
      }
    }
  }
  ll count(node *x) { return x == nullptr ? 0 : x->cnt; }
  ll sum(node *x) { return x == nullptr ? 0 : x->sum; }
  node *update(node *x) {
    x->cnt = count(x->lp) + count(x->rp) + 1;
    x->sum = sum(x->lp) + sum(x->rp) + x->val;
    return x;
  }
  void push(node *x) {
    if (x->rev) {
      swap(x->lp, x->rp);
      if (x->lp != nullptr)
        x->lp->rev = !x->lp->rev;
      if (x->rp != nullptr)
        x->rp->rev = !x->rp->rev;
      x->rev = false;
    }
  }
  void toggle(node *x) { x->rev = !x->rev, push(x); }
  node *expose(node *x) {
    node *rp = nullptr;
    for (node *p = x; p != nullptr; p = p->pp)
      splay(p), p->rp = rp, rp = p, update(p);
    splay(x);
    return rp;
  }
  void cut(node *c) {
    expose(c);
    node *p = c->lp;
    c->lp = p->pp = nullptr;
  }
  void cutb(node *u, node *v) { evert(u), cut(v); }
  void link(node *c, node *p) { expose(c), expose(p), c->pp = p, p->rp = c; }
  void linkb(node *u, node *v) { evert(u), evert(v), link(u, v); }
  void evert(node *x) { expose(x), toggle(x), push(x); }
  node *get_root(node *x) {
    expose(x);
    while (x->lp != nullptr)
      push(x), x = x->lp;
    // splay(x);
    return x;
  }
  node *lca(node *u, node *v) {
    return get_root(u) == get_root(v) ? (expose(u), expose(v)) : nullptr;
  }
  ll path_sum(node *u, node *v) {
    evert(u), expose(v);
    return v->val + sum(v->lp);
  }
  node *update_val(node *x, ll val) {
    expose(x), x->val = val, splay(x);
    return x;
  }
  node *make_node(ll idx = 0, ll dat = 0, ll val = 0) {
    return new node(idx, dat, val);
  }
} lct;

signed main() {
  ll N, Q, A, B, C;
  cin >> N >> Q;
  vector<link_cut_tree::node *> V;
  rep(i, N) V.pb(lct.make_node(i));
  rep(i, Q) {
    cin >> A >> B >> C;
    if (A == 0)
      lct.linkb(V[B], V[C]);
    if (A == 1)
      cout << (lct.get_root(V[B]) == lct.get_root(V[C])) << rt;
  }
}

#include <bits/stdc++.h>
using namespace std;
// #pragma GCC target("arch=skylake-avx512")
// export CPLUS_INCLUDE_PATH="/Users/shuzaei/Desktop/ac-library
// /usr/bin/env python3 "/Users/shuzaei/Desktop/ac-library/expander.py"
// /Users/shuzaei/Desktop/Solve.cpp
#include <atcoder/dsu>
using namespace atcoder;

#pragma region template

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr const ll dx[4] = {1, 0, -1, 0};
constexpr const ll dy[4] = {0, 1, 0, -1};
constexpr const ll MOD = 1e9 + 7;
constexpr const ll mod = 998244353;
constexpr const ll INF = 1LL << 60;
constexpr const ll inf = 1 << 30;
constexpr const char rt = '\\n';
constexpr const char sp = ' ';
#define rt(i, n) (i == (ll)(n)-1 ? rt : sp)
#define len(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ifn(x) if (not(x))
#define elif else if
#define elifn else ifn
#define fi first
#define se second
#define uniq(x) (sort(all(x)), (x).erase(unique(all(x)), (x).end()))
#define bis(x, y) ((ll)(lower_bound(all(x), y) - (x).begin()))

using graph = vector<vector<ll>>;
template <class T> using wgraph = vector<vector<pair<ll, T>>>;
bool __DIRECTED__ = true;
bool __ZERO_INDEXED__ = false;
istream &operator>>(istream &is, graph &g) {
  ll a, b;
  is >> a >> b;
  if (__ZERO_INDEXED__ == false)
    a--, b--;
  g[a].pb(b);
  if (__DIRECTED__ == false)
    g[b].pb(a);
  return is;
}
template <class T> istream &operator>>(istream &is, wgraph<T> &g) {
  ll a, b;
  T c;
  is >> a >> b >> c;
  if (__ZERO_INDEXED__ == false)
    a--, b--;
  g[a].pb({b, c});
  if (__DIRECTED__ == false)
    g[b].pb({a, c});
  return is;
}

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

// Debug
#define debug(...)                                                             \\
  {                                                                            \\
    cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                         \\
    for (auto &&__i : {__VA_ARGS__})                                           \\
      cerr << "[" << __i << "] ";                                              \\
    cerr << rt;                                                                \\
  }

#define dump(a, h, w)                                                          \\
  {                                                                            \\
    cerr << __LINE__ << ": " << #a << " = [" << rt;                            \\
    rep(__i, h) {                                                              \\
      rep(__j, w) {                                                            \\
        if (abs(a[__i][__j]) >= INF / 2 and a[__i][__j] <= -INF / 2)           \\
          cerr << '-';                                                         \\
        if (abs(a[__i][__j]) >= INF / 2)                                       \\
          cerr << "∞" << sp;                                                   \\
        else                                                                   \\
          cerr << a[__i][__j] << sp;                                           \\
      }                                                                        \\
      cerr << rt;                                                              \\
    }                                                                          \\
    cerr << "]" << rt;                                                         \\
  }

#define vdump(a, n)                                                            \\
  {                                                                            \\
    cerr << __LINE__ << ": " << #a << " = [";                                  \\
    rep(__i, n) {                                                              \\
      if (__i)                                                                 \\
        cerr << sp;                                                            \\
      if (abs(a[__i]) >= INF / 2 and a[__i] <= -INF / 2)                       \\
        cerr << '-';                                                           \\
      if (abs(a[__i]) >= INF / 2)                                              \\
        cerr << "∞" << sp;                                                     \\
      else                                                                     \\
        cerr << a[__i];                                                        \\
    }                                                                          \\
    cerr << "]" << rt;                                                         \\
  }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)

// Stream
#define fout(n) cout << fixed << setprecision(n)
struct io {
  io() { cin.tie(nullptr), ios::sync_with_stdio(false); }
} io;

// Speed
#pragma GCC target(                                                            \\
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast,unroll-loops")

// Math
inline constexpr ll gcd(const ll a, const ll b) {
  return b ? gcd(b, a % b) : a;
}
inline constexpr ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }

inline constexpr ll modulo(const ll n, const ll m = MOD) {
  ll k = n % m;
  return k + m * (k < 0);
}
inline constexpr ll chmod(ll &n, const ll m = MOD) {
  n %= m;
  return n += m * (n < 0);
}
inline constexpr ll mpow(ll a, ll n, const ll m = MOD) {
  ll r = 1;
  rep(i, 64) {
    if (n & (1LL << i))
      r *= a;
    chmod(r, m);
    a *= a;
    chmod(a, m);
  }
  return r;
}
inline ll inv(const ll n, const ll m = MOD) {
  ll a = n, b = m, x = 1, y = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    x -= t * y;
    swap(x, y);
  }
  return modulo(x, m);
}

#pragma endregion

signed main() {
  ll N, Q;
  cin >> N >> Q;
  dsu uf(N);
  rep(i, Q) {
    ll A, B, C;
    cin >> A >> B >> C;
    if (A == 0)
      uf.merge(B, C);
    if (A == 1)
      cout << uf.same(B, C) << rt;
  }
}


// #pragma warning(disable:4996)
// #include <Windows.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
#include <bitset>
#include <complex>
#include <cstdio>
#include <list>
// #include <stdio.h>

//< in.txt > out.txt
using namespace std;
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
// typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;
template <class T>
using pqueue = priority_queue<T, vector<T>, function<bool(T, T)>>;

template <class T> inline void chmin(T &a, T b) { a = min(a, b); }

template <class T> inline void chmax(T &a, T b) { a = max(a, b); }

void input();
void solve();

void daminput();
void naive();

void outputinput();

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  input();
  // daminput();
  solve();
  // naive();
  // outputinput();
  return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////

int N, Q;
VI T, U, V;

void input() {
  cin >> N >> Q;
  T.resize(Q);
  U.resize(Q);
  V.resize(Q);
  for (int n = 0; n < N; n++) {
    cin >> T[n] >> U[n] >> V[n];
  }
}

void daminput() {}

// unionFind
class unionFind {
private:
  int *p; // 親配列のポインタ
  int *rank;
  int N;      // 要素数
  int *check; // 同値な要素の数
public:
  unionFind(int);      // コンストラクタ
  int parent(int);     // 親要素を返す
  void unit(int, int); // 2要素をつなぐ
  int operator[](int); // parentの省略形
  ~unionFind();
  int size(int n); // 頂点nと同値な要素数を返す
};

unionFind::unionFind(int n) {
  N = n;
  p = new int[N];
  rank = new int[N];
  for (int i = 0; i < N; i++) {
    p[i] = i;
    rank[i] = 0;
  }
  check = new int[N];
  for (int n = 0; n < N; n++)
    check[n] = 1;
  return;
}

int unionFind::parent(int n) {
  if (n < 0 || n >= N)
    return -1;
  if (p[n] == n)
    return n;                 // 自分が一番上の親
  return p[n] = parent(p[n]); // つなぎ直しと上にたどる操作
}

int unionFind::operator[](int n) { return parent(n); }

void unionFind::unit(int x, int y) {
  x = parent(x), y = parent(y);
  if (x == y)
    return; // 根が同じだから何もせずに帰る
  int sum = check[x] + check[y];
  if (rank[x] < rank[y])
    p[x] = y;
  else {
    p[y] = x;
    if (rank[x] == rank[y])
      rank[x]++;
  }
  check[x] = sum;
  check[y] = sum;
  return;
}

unionFind::~unionFind() {
  delete (p);
  delete (rank);
  delete (check);
  return;
}

int unionFind::size(int n) { return check[parent(n)]; }

void solve() {
  unionFind UF(N);
  for (int n = 0; n < N; n++) {
    if (T[n] == 0) {
      UF.unit(U[n], V[n]);
    } else {
      if (UF[U[n]] == UF[V[n]]) {
        cout << 1 << "\\n";
      } else
        cout << 0 << "\\n";
    }
  }
}

void naive() {}

void outputinput() {}

// #pragma warning(disable:4996)
// #include <Windows.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
#include <bitset>
#include <complex>
#include <cstdio>
#include <list>
// #include <stdio.h>

//< in.txt > out.txt
using namespace std;
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
// typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;
template <class T>
using pqueue = priority_queue<T, vector<T>, function<bool(T, T)>>;

template <class T> inline void chmin(T &a, T b) { a = min(a, b); }

template <class T> inline void chmax(T &a, T b) { a = max(a, b); }

void input();
void solve();

void daminput();
void naive();

void outputinput();

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  input();
  // daminput();
  solve();
  // naive();
  // outputinput();
  return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////

int N, Q;
VI T, U, V;

void input() {
  cin >> N >> Q;
  T.resize(Q);
  U.resize(Q);
  V.resize(Q);
  for (int n = 0; n < Q; n++) {
    cin >> T[n] >> U[n] >> V[n];
  }
}

void daminput() {}

// unionFind
class unionFind {
private:
  int *p; // 親配列のポインタ
  int *rank;
  int N;      // 要素数
  int *check; // 同値な要素の数
public:
  unionFind(int);      // コンストラクタ
  int parent(int);     // 親要素を返す
  void unit(int, int); // 2要素をつなぐ
  int operator[](int); // parentの省略形
  ~unionFind();
  int size(int n); // 頂点nと同値な要素数を返す
};

unionFind::unionFind(int n) {
  N = n;
  p = new int[N];
  rank = new int[N];
  for (int i = 0; i < N; i++) {
    p[i] = i;
    rank[i] = 0;
  }
  check = new int[N];
  for (int n = 0; n < N; n++)
    check[n] = 1;
  return;
}

int unionFind::parent(int n) {
  if (n < 0 || n >= N)
    return -1;
  if (p[n] == n)
    return n;                 // 自分が一番上の親
  return p[n] = parent(p[n]); // つなぎ直しと上にたどる操作
}

int unionFind::operator[](int n) { return parent(n); }

void unionFind::unit(int x, int y) {
  x = parent(x), y = parent(y);
  if (x == y)
    return; // 根が同じだから何もせずに帰る
  int sum = check[x] + check[y];
  if (rank[x] < rank[y])
    p[x] = y;
  else {
    p[y] = x;
    if (rank[x] == rank[y])
      rank[x]++;
  }
  check[x] = sum;
  check[y] = sum;
  return;
}

unionFind::~unionFind() {
  delete (p);
  delete (rank);
  delete (check);
  return;
}

int unionFind::size(int n) { return check[parent(n)]; }

void solve() {
  unionFind UF(N);
  for (int n = 0; n < Q; n++) {
    if (T[n] == 0) {
      UF.unit(U[n], V[n]);
    } else {
      if (UF[U[n]] == UF[V[n]]) {
        cout << 1 << "\\n";
      } else
        cout << 0 << "\\n";
    }
  }
}

void naive() {}

void outputinput() {}


#include <iostream>
#include <vector>

using namespace std;

struct Unionfind {
  vector<int> par;
  vector<int> rank;

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

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

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

  bool issame(int x, int y) { return root(x) == root(y); }
};

int main() {
  int n, q;
  cin >> n >> q;
  Unionfind uf;
  uf.init(n);
  for (int i = 0; i < q; i++) {
    int query, a, b;
    cin >> query >> a >> b, a--, b--;
    if (query == 0)
      uf.unite(a, b);
    else
      cout << (uf.issame(a, b) ? 1 : 0) << endl;
  }
}

#include <iostream>
#include <vector>

using namespace std;

struct Unionfind {
  vector<int> par;
  vector<int> rank;

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

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

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

  bool issame(int x, int y) { return root(x) == root(y); }
};

int main() {
  int n, q;
  cin >> n >> q;
  Unionfind uf;
  uf.init(n);
  for (int i = 0; i < q; i++) {
    int query, a, b;
    cin >> query >> a >> b;
    if (query == 0)
      uf.unite(a, b);
    else
      cout << (uf.issame(a, b) ? 1 : 0) << endl;
  }
}