UVA 10608 Friends

來源:互聯網
上載者:User

標籤:

Friends(8.4.1)Crawling in process...Crawling failedTime Limit:3000MS    Memory Limit:0KB     64bit IO Format:%lld & %lluSubmitStatus

Description


 

There is a town with N citizens. It is known that some pairs of people are friends. According to the famous saying that “The friends of my friends are my friends, too” it follows that if A and B are friends and B and C are friends then A and C are friends, too.

 

Your task is to count how many people there are in the largest group of friends.

 

Input

Input consists of several datasets. The first line of the input consists of a line with the number of test cases to follow. The first line of each dataset contains tho numbers N and M, where N is the number of town‘s citizens (1≤N≤30000) and M is the number of pairs of people (0≤M≤500000), which are known to be friends. Each of the following M lines consists of two integers A and B (1≤A≤N, 1≤B≤N, A≠B) which describe that A and B are friends. There could be repetitions among the given pairs.

 

Output

The output for each test case should contain one number denoting how many people there are in the largest group of friends.

 

Sample Input

Sample Output

2

3 2

1 2

2 3

10 12

1 2

3 1

3 4

5 4

3 5

4 6

5 2

2 1

7 10

1 2

9 10

8 9

3

6

 


#include <iostream>#include <cstring>#define maxn 30005using namespace std;int f[maxn],ans[maxn];int find(int x){    if(f[x]==x)        return x;    else        return(f[x]=find(f[x])); }int main(){    int N;cin>>N;    while(N--)    { int n,m;cin>>n>>m;int i;for(i=1;i<=n;i++)f[i]=i;memset(ans,0,sizeof(ans));for(i=1;i<=m;i++){int x,y;cin>>x>>y;int fx,fy;fx=find(x);fy=find(y);if(fx!=fy)f[fx]=fy;}for(i=1;i<=n;i++)ans[find(i)]++;int max=0;for(i=1;i<=n;i++)if(ans[i]>max)max=ans[i];cout<<max<<endl;    }    return 0;}


代碼還沒有ac。不管是在UVA上還是虛擬oj上都顯示,In judge queue

表示非常無語,等了好長時間,虛擬oj顯示  Judging Error 2。淡淡的憂桑。

。



更新:已經ac


著作權聲明:本文部落格原創文章,部落格,未經同意,不得轉載。

UVA 10608 Friends

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.