qjx
cookiebus
2024-05-04 15:58:56
2024-05-04 15:59:06
9
返回题目
#include <bits/stdc++.h>
using namespace std;
int a[10000], cnt[20000], n, m, ans = 0;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
a[i] = i;
}
for (int i = 0; i < m; i++) {
int x, y;
char l;
cin >> l >> x >> y;
if (l == 'F') {
for (int i = 1; i <= n; i++) {
if (a[i] == a[x] && i != x) {
a[i] = a[y];
}
if (a[i] == -a[x] && i != x) {
a[i] = -a[y];
}
}
a[x] = a[y];
} else {
for (int i = 1; i <= n; i++) {
if (a[i] == a[x] && i != x) {
a[i] = -a[y];
}
if (a[i] == -a[x] && i != x) {
a[i] = a[y];
}
}
a[x] = -a[y];
}
}
for (int i = 1; i <= n; i++) {
cnt[a[i] + 10000]++;
}
for (int i = 0; i < 20000; i++) {
ans = max(cnt[i], ans);
}
cout << ans;
return 0;
}
{{ vote && vote.total.up }}