#region ZIPPER
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using sc = Scanner;
using Geometry;
using gl = Geometry.GeometryLibrary;
class Program
{
    static void Main(string[] args)
    {
        Solver solver = new Solver();
        solver.Solve();
#if DEBUG
        System.Console.WriteLine("?¶?????????????????????????????????????????????????????????????");
        System.Console.ReadKey();
#endif

    }
}
/// <summary>
/// ?¨??????\????????????????????´???????????????????????????????????????
/// </summary>
public static class Scanner
{
    public static string NextString()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return tmp;
    }
    public static int NextInt()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return int.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return long.Parse(tmp);
    }
    public static double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return double.Parse(tmp);
    }

    public static string[] NextStrArray()
    {
        return Console.ReadLine().Split(' ');
    }
    public static int[] NextIntArray()
    {

        string[] s = NextStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }
    public static long[] NextLongArray()
    {
        string[] s = NextStrArray();
        long[] a = new long[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = long.Parse(s[i]);
        }
        return a;
    }
    public static double[] NextDoubleArray()
    {
        string[] s = NextStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }
}
#endregion ZIPPER

public class Solver
{
#region IGNORE_ME
    public Solver()
    {
        //???????????¨?????????????????????????????????????????????
    }
#endregion IGNORE_ME

    public void Solve()
    {
        int n = sc.NextInt();
        int q = sc.NextInt();
        int[][] data = new int[q][];
        for (int i = 0; i < q; i++)
        {
            data[i] = sc.NextIntArray();
        }
        UnionFindTree uf = new UnionFindTree(n);
        for (int i = 0; i < q; i++)
        {
            if (data[i][0] == 0)
            {
                uf.Unite(data[i][1],data[i][2]);
            }else
            {
                Console.WriteLine("{0}",uf.Same(data[i][1],data[i][2])?"1":"0");
            }
        }
#if DEBUG
        Console.WriteLine("");//local check
#endif
    }
}
/// <summary>
/// UF??¨????????¬??????
/// </summary>
public class UnionFindTree
{
    int[] Par;
    int[] Rank;
    /// <summary>
    /// n???????´???°???????????????UF??¨
    /// </summary>
    /// <param name="n"></param>
    public UnionFindTree(int n)
    {
        this.Par = new int[n];
        this.Rank = new int[n];
        for (int i = 0; i < n; i++)
        {
            Par[i] = i;
        }
    }
    /// <summary>
    /// ??¨??????????±???????
    /// </summary>
    /// <param name="x"></param>
    /// <returns></returns>
    private int Find(int x)
    {
        if (Par[x] == x)
            return x;
        else
        {
            Par[x] = Find(Par[x]);
            return Par[x];
        }
    }
    /// <summary>
    /// x??¨y????±??????????????????????
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    public void Unite(int x, int y)
    {
        x = Find(x);
        y = Find(y);
        if (x == y) return;
        if (Rank[x] < Rank[y])
        {
            Par[x] = y;
        }
        else
        {
            Par[y] = x;
            if(Rank[x]==Rank[y])Rank[x]++;
        }
    }
    /// <summary>
    /// x??¨y???????????????????±????????????????
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    public bool Same(int x,int y)
    {
        return Find(x) == Find(y);
    }
}

namespace Geometry
{
    /// <summary>
    /// ??????x,y??§?¨??????¨???(double???)
    /// </summary>
    public struct dPoint
    {
        public double x;
        public double y;
        public dPoint(int x, int y)
        {
            this.x = (double)x; this.y = (double)y;
        }
        public dPoint(double x, double y)
        {
            this.x = x; this.y = y;
        }
        public static dPoint operator +(dPoint p1, dPoint p2)
        {
            return new dPoint(p1.x + p2.x, p1.y + p2.y);
        }
        public static dPoint operator -(dPoint p1, dPoint p2)
        {
            return new dPoint(p1.x - p2.x, p1.y - p2.y);
        }
        public static dPoint operator *(double s, dPoint p)
        {
            return new dPoint(s * p.x, s * p.y);
        }
    }
    /// <summary>
    /// ??????x,y??§?¨??????¨???(int???)
    /// </summary>
    public struct Point
    {
        public int x;
        public int y;
        public Point(int x, int y)
        {
            this.x = x; this.y = y;
        }
        public static Point operator +(Point p1, Point p2)
        {
            return new Point(p1.x + p2.x, p1.y + p2.y);
        }
        public static Point operator -(Point p1, Point p2)
        {
            return new Point(p1.x - p2.x, p1.y - p2.y);
        }
        public static Point operator *(int s, Point p)
        {
            return new Point(s * p.x, s * p.y);
        }
    }

    public static class GeometryLibrary
    {


        /// <summary>
        /// ??????
        /// </summary>
        /// <returns></returns>
        public static double Naiseki(dPoint p1, dPoint p2)
        {
            return p1.x * p2.x + p1.y * p2.y;
        }
        /// <summary>
        /// ??????
        /// </summary>
        /// <returns></returns>
        public static int Naiseki(Point p1, Point p2)
        {
            return p1.x * p2.x + p1.y * p2.y;
        }
        /// <summary>
        /// ??´???p1,p2???????????????p????°???±
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static dPoint Projection(dPoint p1, dPoint p2, dPoint p)
        {
            dPoint a = p2 - p1;
            dPoint b = p - p1;
            double t = Naiseki(a, b) / Naiseki(a, a);
            return t * a + p1;
        }
        /// <summary>
        /// ??´???p1p2???????????????p???????°????p1,p2???????????´?????????????§°??????p????§????
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static dPoint Refrection(dPoint p1, dPoint p2, dPoint p)
        {
            return 2 * Projection(p1, p2, p) - p;
        }

        /// <summary>
        /// p1p2??¨p3p4???2??´????????????
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <param name="p4"></param>
        /// <returns></returns>
        public static bool IsParallel(Point p1, Point p2, Point p3, Point p4)
        {
            Point a = p2 - p1;
            Point b = p4 - p3;
            if (Naiseki(a, b) * Naiseki(a, b) == Naiseki(a, a) * Naiseki(b, b)) return true;
            return false;
        }
        /// <summary>
        ///  p1p2??¨p3p4???2??´???????????´
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <param name="p4"></param>
        /// <returns></returns>
        public static bool IsVertical(Point p1, Point p2, Point p3, Point p4)
        {
            Point a = p2 - p1;
            Point b = p4 - p3;
            if (Naiseki(a, b) == 0) return true;
            return false;
        }

        /// <summary>
        ///  p1p2??¨p3p4???2????????????????????? ?????????http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Intersection.htm
        ///  ?????´?????????3????????¨????????´??????????????????????????????????????¨????????????
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <param name="p4"></param>
        /// <returns></returns>
        public static bool DoesIntersect(Point p1, Point p2, Point p3, Point p4)
        {
            Point a = p1 - p2;
            Point b = p3 - p1;
            Point c = p4 - p1;
            long tc = a.x * b.y + a.y * (-b.x);
            long td = a.x * c.y + a.y * (-c.x);
            Point d = p3 - p4;
            Point e = p1 - p3;
            Point f = p2 - p3;
            long ta = d.x * e.y + d.y * (-e.x);
            long tb = d.x * f.y + d.y * (-f.x);
            if (tc * td < 0 && ta * tb < 0) return true;
            if (ta == 0 //???p1???p3p4?????´??????????????£?????????????????£?????????p2?????´???
                && Math.Min(p3.x, p4.x) <= p1.x && p1.x <= Math.Max(p3.x, p4.x)
                && Math.Min(p3.y, p4.y) <= p1.y && p1.y <= Math.Max(p3.y, p4.y)
                )
                return true;
            if (tb == 0 
                && Math.Min(p3.x, p4.x) <= p2.x && p2.x <= Math.Max(p3.x, p4.x)
                && Math.Min(p3.y, p4.y) <= p2.y && p2.y <= Math.Max(p3.y, p4.y)
                )
                return true;
            if (tc == 0  //???p3???p1p2?????´??????????????£?????????????????£?????????p4?????´???
                && Math.Min(p1.x, p2.x) <= p3.x && p3.x <= Math.Max(p1.x, p2.x)
                && Math.Min(p1.y, p2.y) <= p3.y && p3.y <= Math.Max(p1.y, p2.y)
                )
                return true;
            if (tb == 0
                && Math.Min(p1.x, p2.x) <= p4.x && p4.x <= Math.Max(p1.x, p2.x)
                && Math.Min(p1.y, p2.y) <= p4.y && p4.y <= Math.Max(p1.y, p2.y))
                return true;
            return false;
        }
    }
}

Measured memory_bytes: 19756