#include<cstdio> #include<cstring> using namespace std; int parent[30001]; int level[30001]; int findparent(int n) { return parent[n]==n? n: findparent(parent[n]); } int main() { int n,m,tc,a,b; scanf("%d",&tc); while (tc--) { scanf("%d%d",&n,&m); if (m+n==0) return 0; n++; for (int i=1;i<n;i++) { parent[i]=i; level[i]=1; } while (m--) { scanf("%d%d",&a,&b); a=findparent(a); b=findparent(b); if (a!=b) { parent[a]=b; level[b]+=level[a]; } } bool visited[n]; memset(visited,false,sizeof(visited)); int max=0; for (int i=1;i<n;i++) { if (max<level[i]) max=level[i]; } printf("%d\n",max); } return 0; }
Saturday, June 25, 2016
UVA 10608 Solution
Unknown
Studying at Shahjalal University of Science and Technology, Sylhet.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment