#include <iostream>
#include <algorithm>
using namespace std;
int root(int a,int P[]);

int root(int a,int P[])
{
    if(P[a] == a)
        return a;
    else    return (P[a] = root(P[a],P));
}
int is_same_set(int a,int b,int P[])
{
    return root(a,P) == root(b,P);
}

int main()
{
    int n,q,i,com,x,y,flag;
    cin >> n >> q;
    int P[n];
    for(i=0;i<n;i++)
        P[i] = i;
    for(i=0;i<q;i++)
    {
        cin >> com >> x >> y;
        if(com == 0)
            P[root(x,P)] = root(y,P);
        else    if(com == 1)
                {
                    flag = is_same_set(x,y,P);
                    cout << flag << endl;
                }
    }
    return 0;
}
