题目1444:More is better

来源:互联网 发布:2011年小牛夺冠数据 编辑:程序博客网 时间:2024/05/22 16:02
#include <stdio.h>#define max 10000010int tree[max];int people[max];int findroot(int x){    if(tree[x]==-1)        return x;    else    {        int tap=findroot(tree[x]);        tree[x]=tap;        return tap;    }}int main(){    int n,a,b;    while(scanf("%d",&n)!=EOF)    {        for (int i = 0; i < max; ++i)        {            tree[i]=-1;            people[i]=1;        }        while(n--)        {            scanf("%d %d",&a,&b);            a =findroot(a);            b =findroot(b);            if(a!=b)            {                tree[a]=b;                people[b]+=people[a];            }        }        int people_max=0;        int index=0;        for (int i = 0; i < max; ++i)        {            if(people[i]>people_max)            {                people_max=people[i];                index=i;            }        }        printf("%d\n",people_max);    }    return 0;}/**************************************************************    Problem: 1444    User: cust123    Language: C++    Result: Accepted    Time:880 ms    Memory:79144 kb****************************************************************/

0 0
原创粉丝点击