#include<bits/stdc++.h> int t[99999],n,q,a,b,c;int r(int x){return t[x]<=0?x:(t[x]=r(t[x]));}int main(){for(std::cin>>n>>q;q--;){std::cin>>a>>b>>c;b=r(b);c=r(c);if(a)puts(b==c?"YES":"NO");else b!=c&&(t[c]=b);}}
Note that non-ascii characters in the above source code will be escaped (such as \x9f).