#include<iostream> #include<cstdio> #include<algorithm> #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl #define db3(a, b, c) cout << #a << " = " << a << " " << #b << " = " << b << " " << #c << " = " << c << endl #define MAX 30001 using namespace std; int P[MAX], mejor[MAX]; int find(int i) { return P[i] == -1 ? i : P[i] = find(P[i]); } void join(int i, int j) { if (find(i) != find(j)) P[find(i)] = find(j);} void init(int n) { fill(P, P + n, -1);} int main() { int n, m, a, b, t; scanf("%d", &t); while (t--) { scanf("%d %d", &n, &m); init(n + 1); for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); join(a, b); } fill(mejor, mejor + n + 1, 0); for (int i = 1; i < n + 1; i++) mejor[find(i)]++; int res = *max_element(mejor, mejor + n + 1); printf("%d\n", res); } return 0; }
jueves, 24 de noviembre de 2011
10608 - Friends, uva
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario