#include<bits/stdc++.h> usingnamespace std; typedeflonglong ll; constint N = 10009; int fa[N]; // 存储每个节点的父节点 intfind(int x) { // 如果 fa[x] == x 则x是该树的根节点 return fa[x] == x ? x : find(fa[x]); } voidmerge(int a, int b) { // 合并两棵树 a = find(a); b = find(b); if (a != b) fa[a] = b; } intmain() { std::ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) fa[i] = i; // 初始化 while (m--) { int z, x, y; cin >> z >> x >> y; if (z == 1) merge(x, y); else cout << ((find(x) == find(y)) ? "Y" : "N") << '\n'; } return0; }