#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define MAXN 300010

using namespace std;

vector <ll> DSU(MAXN);
vector <ll> SIZE(MAXN);

ll root(ll X)
{
    if(X == DSU[X]) return X;
    return DSU[X] = root(DSU[X]);
}

void spoji(ll X, ll Y)
{
    X = root(X);
    Y = root(Y);
    if(X == Y) return;
    if(SIZE[X] < SIZE[Y]) swap(X, Y);
    DSU[Y] = X;
    SIZE[X] += SIZE[Y];
    SIZE[Y] = 0;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    for(int i = 0; i < MAXN; i++) {DSU[i] = i; SIZE[i] = 1;}
    ll N, Q, X, Y;
    ll tip;
    char ch;
    cin >> N >> Q;
    while(Q--)
    {
        cin >> tip;
        if(tip == 1)
        {
            cin >> X >> Y >> ch;
            spoji(X, Y);
        }
        else
        {
            cin >> X >> Y;
            if(root(X) != root(Y)) cout << 0 << endl;
            else cout << 1 << endl;
        }
    }
    return 0;
}
/**

**/