0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 06:51:58 +00:00
OI-codes/AcWing/836/836.cpp

27 lines
495 B
C++

#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, fa[100005];
char op;
int getfa(int x) {
return fa[x] == x ? fa[x] : fa[x] = getfa(fa[x]);
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
fa[i] = i;
}
for (int i = 0; i < m; i++) {
cin >> op >> a >> b;
if (op == 'M') {
fa[getfa(a)] = getfa(b);
} else {
cout << (getfa(a) == getfa(b) ? "Yes" : "No") << endl;
}
}
return 0;
}