mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-05 12:18:48 +00:00
27 lines
495 B
C++
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;
|
||
|
}
|