#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]);
}
/*
5 6
1 1 2 a
1 5 6 a
2 2 5
1 1 6 a
2 2 5
1 3 4 a
*/
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[fun(a)] = par[fun(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;
}