#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
long long par[1000001];
long long fun(long long v)
{
    if (par[v] == v) return v;
    return par[v] = fun(par[v]);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long long n, q, i, t, a, b;
    char c;
    cin >> n >> q;
    for (i = 1; i <= n; i++)
    {
        par[i] = i;
    }
    while (q--)
    {
        cin >> t >> a >> b;
        if (t == 1)
        {
            par[a] = par[b];
            cin >> c;
            continue;
        }
        par[a] = fun(a);
        par[b] = fun(b);
        if (par[a] == par[b])
        {
            cout << 1 << endl;
        }
        else cout << 0 << endl;
    }
    return 0;
}