0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:48:48 +00:00
Baoshuo Ren 2021-09-12 16:07:25 +08:00 committed by Baoshuo Ren
parent d08421fad2
commit b85894c1ec
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

26
AcWing/836/836.cpp Normal file
View File

@ -0,0 +1,26 @@
#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;
}