#include <bits/stdc++.h>
//#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
//#define endl "\n"

using namespace std;

const int MAXN = 1e3+5;
vector<int> parents;

int findparent(int x)
{
    if(parents[x]!=x)parents[x] = findparent(x);
    return parents[x];
}

void connectCMP(int a, int b)
{
    parents[b] = findparent(a);
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt=1;
    //cin >> tt;
    while(tt--)
    {
        int n,q;
        cin >> n >> q;
        parents = vector<int>(n+1);
        for(int i=1; i<=n; i++)parents[i] = i;
        while(q--)
        {
            int t;cin >> t;
            if(t== 1)
            {
                int a,b;char c;
                cin >> a >> b >> c;
                connectCMP(a,b);
            }
            else
            {
                int a, b;
                cin >> a >> b;
                //findparent(a);
                //findparent(b);
                if(parents[a] == parents[b])cout <<1 <<endl;
                else cout << 0 << endl;
            }
        }


    }
}