def find_parent(parent,x):
    if parent[x]!=x:
        parent[x]=find_parent(parent,parent[x])
    return parent[x]

def union_parent(parent,a,b):
    a=find_parent(parent,a)
    b=find_parent(parent,b)

    if a<b:
        parent[b]=a
    else:
        parent[a]=b

n,m=map(int,input().split()) # n: 학생수, m: 연산의수

parent=[0]*(n+1) #부모 테이블 초기화

for i in range(n+1):
    parent[i]=i
answer=[]
for i in range(m):
    choice,a,b=map(int,input().split())

    if choice==0:
        union_parent(parent,a,b)
    else:
        if find_parent(parent,a)==find_parent(parent,b):
            answer.append('YES')
        else:
            answer.append('NO')

for i in answer:
    print(i)
