#include <bits/stdc++.h>
usingnamespacestd;//처음에 u 배열 -1로 초기화.intu[1000001];intfind(inta){if(u[a]<0)returna;returnu[a]=find(u[a]);}boolmerge(inta,intb){a=find(a),b=find(b);if(a==b)returnfalse;//union by rank. path compression을 하지 않을 때 사용.//if(-u[a]<-u[b])swap(a,b);u[a]+=u[b],u[b]=a;returntrue;}intmain(void){intn,m;scanf("%d %d",&n,&m);fill(u,u+1+n,-1);while(m--){intc,a,b;scanf("%d %d %d",&c,&a,&b);if(c)printf(find(a)==find(b)?"YES\n":"NO\n");elsemerge(a,b);}return0;}