using System;
using System.Collections.Generic;

class Program{

    const int INT_MAX = 2147483647;
    static void Main(string[] args)
    {
        int[] nq = Scan.IntArray(2);
        UnionFind uf = new UnionFind();
        uf.Init(nq[0]);
        for (int i = 0; i < nq[1]; i++)
        {
            int[] pab = Scan.IntArray(3);
            if(pab[0] == 0)
            {
                uf.Unite(pab[1], pab[2]);
            }
            else
            {
                Console.WriteLine(uf.Same(pab[1], pab[2]) ? 1 : 0);
            }
        }
    }
}


public class Scan
{
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }

    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }

    public static string[] StringArray(int lines)
    {
        string[] str = new string[lines];
        for (int i = 0; i < lines; i++)
        {
            str[i] = Console.ReadLine();
        }
        return str;
    }

    public static int[] IntArray(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] ar = new int[t];
        for (int i = 0; i < t; i++)
        {
            ar[i] = int.Parse(str[i]);
        }
        return ar;
    }

    public static string[] StringArrayInLine(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        return str;
    }

    public static Tuple<int, int> ScanTuple()
    {
        int[] tmp = Scan.IntArray(2);
        return new Tuple<int, int>(tmp[0], tmp[1]);
    }

    public static long[] LongArray(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] ar = new long[t];
        for (int i = 0; i < t; i++)
        {
            ar[i] = long.Parse(str[i]);
        }
        return ar;
    }

    public static double[] DoubleArray(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] ar = new double[t];
        for (int i = 0; i < t; i++)
        {
            ar[i] = double.Parse(str[i]);
        }
        return ar;
    }

    public static int[,] IntSquareArray(int h, int w)
    {
        int[,] resAr = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            int[] ar = Scan.IntArray(w);
            for (int j = 0; j < w; j++)
            {
                resAr[i, j] = ar[j];
            }
        }
        return resAr;
    }
}

public class Out
{
    public static void Num<T>(T a)
    {
        Console.WriteLine(a);
    }
    public static void Array<T>(T[] a)
    {
        for (int i = 0; i < a.Length; i++)
        {
            Console.Write(a[i]);
            if(i != a.Length - 1)
            {
                Console.Write(" ");
            }
        }
        Console.WriteLine("");
    }

    public static void List<T>(List<T> a)
    {
        for (int i = 0; i < a.Count; i++)
        {
            Console.Write(a[i]);
            if (i != a.Count - 1)
            {
                Console.Write(" ");
            }
        }
        Console.WriteLine("");
    }

}

public class UnionFind
{
    public int[] parent = new int[100005];

    public void Init(int size)
    {
        for (int i = 0; i < size; i++)
        {
            parent[i] = i;
        }
    }

    public int Root(int index)
    {
        if(parent[index] == index)
        {
            return index;
        }
        else
        {
            return parent[index] = Root(parent[index]);
        }
    }

    public void Unite(int x, int y) // Add edge x <- y
    {
        int rx = Root(x);
        int ry = Root(y);
        if(rx != ry)
        {
            parent[ry] = rx;
        }
    }

    public bool Same(int x, int y)
    {
        return Root(x) == Root(y);
    }

}


Measured memory_bytes: 22032