Saturday, June 25, 2016

UVA 10608 Solution

Unknown
#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;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,