d=[] n,q=gets.split.map &:to_i q.times{l=gets;a,x,y=l.split.map{|v|b=v=v.to_i;d[b]=v=d[v]while d[v];v};a<1?x!=y&&d[y]=x :y&&puts(x==y ?:YES: :NO)}