import sys

input = lambda: sys.stdin.readline().rstrip()



# UnionFind

class UnionFind:

  def __init__(self,n):

    self.n=n

    self.a=[-1]*n

    self.r=[0]*n

    self.siz=n

  def root_find(self,x):

    if self.a[x]<0:

      return x

    else:

      self.a[x]=self.root_find(self.a[x])

      return self.a[x]

  def unite(self,x,y):

    x=self.root_find(x)

    y=self.root_find(y)

    if x==y:

      return

    if self.r[x]==self.r[y]:

      self.r[x]+=1

      self.a[x]+=self.a[y]

      self.a[y]=x

    elif self.r[x]>self.r[y]:

      self.a[x]+=self.a[y]

      self.a[y]=x

    else:

      self.a[y]+=self.a[x]

      self.a[x]=y

    self.siz-=1

  def root_same(self,x,y):

      return self.root_find(x)==self.root_find(y)





n,q=list(map(int,input().split()))

u=UnionFind(n)

for _ in range(q):

    t,a,b=list(map(int,input().split()))

    if t==0:

        u.unite(a,b)

    else:

        print((u.root_same(a,b)+0))
import sys

input = lambda: sys.stdin.readline().rstrip()



# UnionFind

class UnionFind:

    def __init__(self,n):

        self.n=n

        self.a=[-1]*n

        self.siz=n

    def root_find(self,x):

        if self.a[x]<0:

            return x

        else:

            self.a[x]=self.root_find(self.a[x])

            return self.a[x]

    def unite(self,x,y):

        x=self.root_find(x)

        y=self.root_find(y)

        if x==y:

          return

        elif self.a[x]<self.a[y]:

            self.a[x]+=self.a[y]

            self.a[y]=x

        else:

            self.a[y]+=self.a[x]

            self.a[x]=y

        self.siz-=1

    def root_same(self,x,y):

        return self.root_find(x)==self.root_find(y)



n,q=list(map(int,input().split()))

u=UnionFind(n)

for _ in range(q):

    t,a,b=list(map(int,input().split()))

    if t==0:

        u.unite(a,b)

    else:

        print((u.root_same(a,b)+0))

import sys

input = lambda: sys.stdin.readline().rstrip()
# UnionFind
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.a = [-1] * n
        self.r = [0] * n
        self.siz = n

    def root_find(self, x):
        if self.a[x] < 0:
            return x
        else:
            self.a[x] = self.root_find(self.a[x])
            return self.a[x]

    def unite(self, x, y):
        x = self.root_find(x)
        y = self.root_find(y)
        if x == y:
            return
        if self.r[x] == self.r[y]:
            self.r[x] += 1
            self.a[x] += self.a[y]
            self.a[y] = x
        elif self.r[x] > self.r[y]:
            self.a[x] += self.a[y]
            self.a[y] = x
        else:
            self.a[y] += self.a[x]
            self.a[x] = y
        self.siz -= 1

    def root_same(self, x, y):
        return self.root_find(x) == self.root_find(y)


n, q = list(map(int, input().split()))
u = UnionFind(n)
for _ in range(q):
    t, a, b = list(map(int, input().split()))
    if t == 0:
        u.unite(a, b)
    else:
        print((u.root_same(a, b) + 0))

import sys

input = lambda: sys.stdin.readline().rstrip()
# UnionFind
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.a = [-1] * n
        self.siz = n

    def root_find(self, x):
        if self.a[x] < 0:
            return x
        else:
            self.a[x] = self.root_find(self.a[x])
            return self.a[x]

    def unite(self, x, y):
        x = self.root_find(x)
        y = self.root_find(y)
        if x == y:
            return
        elif self.a[x] < self.a[y]:
            self.a[x] += self.a[y]
            self.a[y] = x
        else:
            self.a[y] += self.a[x]
            self.a[x] = y
        self.siz -= 1

    def root_same(self, x, y):
        return self.root_find(x) == self.root_find(y)


n, q = list(map(int, input().split()))
u = UnionFind(n)
for _ in range(q):
    t, a, b = list(map(int, input().split()))
    if t == 0:
        u.unite(a, b)
    else:
        print((u.root_same(a, b) + 0))

-        self.r = [0] * n -        if self.r[x] == self.r[y]: -            self.r[x] += 1 -            self.a[x] += self.a[y] -            self.a[y] = x -        elif self.r[x] > self.r[y]: +        elif self.a[x] < self.a[y]: