放guo模板
#include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<cmath> #include<stack> #include<algorithm> using namespace std; #define ll long long #define rg register const int N=10000+5,pw=11,inf=0x3f3f3f3f,P=19650827; int n,m,f[N]; template <class t>void rd(t &x) { x=0;int w=0;char ch=0; while(!isdigit(ch)) w|=ch=='-',ch=getchar(); while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x=w?-x:x; } int find(int x) {return f[x]==x?x:f[x]=find(f[x]);} void Union(int x,int y){f[find(x)]=find(y);} int main() { //freopen("in.txt","r",stdin); //freopen("nocows.out","w",stdout); rd(n),rd(m); for(int i=1;i<=n;++i) f[i]=i; while(m--){ int x,y,z; rd(z),rd(x),rd(y); if(z==1){ Union(x,y); } else{ if(find(x)==find(y)) printf("Y "); else printf("N "); } } return 0; }