#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
const int N=1050;
int par[N];
int FS(int u){
    if(par[u]==u) return u;
    return par[u]=FS(par[u]);
}
void US(int u,int v) {int x=FS(u),y=FS(v);par[x]=y;}
int main()
{
    int n,q;scanf("%i%i",&n,&q);
    for(int i=1;i<=n;i++) par[i]=i;
    while(q--){
        int type;scanf("%i",&type);
        if(type==1){
            int u,v;char c;scanf("%i%i",&u,&v);cin>>c;
            US(u,v);
        }
        else{
            int u,v;scanf("%i%i",&u,&v);
            printf("%i\n",FS(u)==FS(v));
        }
    }
    return 0;
}