文章
34
粉丝
89
获赞
2
访问
19.2k
#include <iostream> #include <cstdio> using namespace std; int fa[10005]; int find(int x){ if(x == fa[x]){ return x; } return fa[x] = find(fa[x]); } int main() { int n,m; cin >> n >> m; for(int i = 1;i <= n;i++){ fa[i] = i; } for(int i = 1;i <= m;i++){ int z,j,k; cin >> z >> j >> k; if(z==1){ fa[find(k)] = find(j); }else if(z == 2){ if(find(j) == find(k)){ cout << "Y" << endl; }else{ cout << "N" << endl; } } } }
登录后发布评论
暂无评论,来抢沙发