标签:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
const int N = 30005;
typedef long long ll;
int n, m;
int f[N], cnt[N];
int find(int x) {
return f[x] == x ? x : f[x] = find(f[x]);
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
f[i] = i;
cnt[i] = 1;
}
int a, b, ans = 0;
for (int i = 0; i < m; i++) {
scanf("%d %d", &a, &b);
int pa = find(a), pb = find(b);
if (pa != pb) {
f[pb] = pa;
cnt[pa] += cnt[pb];
if (cnt[pa] > ans) ans = cnt[pa];
}
}
printf("%d\n", ans);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许也可以转载,不过要注明出处哦。
标签:
原文地址:http://blog.csdn.net/llx523113241/article/details/47303223