2021-11-19 09:01:13 +00:00
|
|
|
#include <bits/stdc++.h>
|
2020-11-01 13:54:10 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int f[1000005];
|
|
|
|
|
|
|
|
int find(int x) {
|
|
|
|
return f[x] == x ? x : f[x] = find(f[x]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int n, m, z, x, y;
|
|
|
|
cin >> n >> m;
|
2021-11-19 09:01:13 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
2020-11-01 13:54:10 +00:00
|
|
|
f[i] = i;
|
|
|
|
}
|
2021-11-19 09:01:13 +00:00
|
|
|
while (m--) {
|
2020-11-01 13:54:10 +00:00
|
|
|
cin >> z >> x >> y;
|
2021-11-19 09:01:13 +00:00
|
|
|
if (z == 1) {
|
2020-11-01 13:54:10 +00:00
|
|
|
f[find(x)] = find(y);
|
2021-11-19 09:01:13 +00:00
|
|
|
} else {
|
2020-11-01 13:54:10 +00:00
|
|
|
cout << (find(x) == find(y) ? "Y" : "N") << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|