#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define INF 1e18
#define maxn 100010
using namespace std;

ll dsu[maxn];

ll root(ll i){
    while(dsu[i]!=i){
        dsu[i]=dsu[dsu[i]];
        i=dsu[i];
    }
    return i;
}
void povezi(ll a, ll b){ dsu[root(a)]=root(b); }
bool povezan(ll a,ll b){ return root(a)==root(b); }

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
    ll n,q; cin>>n>>q;
    for(ll i=1;i<=n;i++) dsu[i]=i;
    for(ll i=1;i<=q;i++){
        int mode; cin>>mode;
        if(mode==1){
            ll a,b; char c; cin>>a>>b>>c;
            povezi(a,b);
        }else{
            ll a,b; cin>>a>>b; cout<<povezan(a,b)<<"\n";
        }
    }
}