#include<bits/stdc++.h>
#define ll long long
#define MAXN 300007
using namespace std;
int p[MAXN];
int get(int u)
{
    if(u==p[u]) return u;
    return p[u]=get(p[u]);
}
void join(int u, int v)
{
    u=get(u);
    v=get(v);
    p[v]=u;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int q;
    cin>>q;
    for(int i=1;i<=n;i++) p[i]=i;
    while(q--)
    {
        int type;
        cin>>type;
        if(type==1)
        {
            int u,v;
            char c;
            cin>>u>>v;
            cin>>c;
            join(u,v);
        }
        else
        {
            int u,v;
            cin>>u>>v;
            if(get(u)==get(v)) cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
    return 0;
}