Ultraviolet A 10608 friends

Source: Internet
Author: User

Friends (8.4.1) Crawling in process... Crawling failed Time limit:3000 Ms Memory limit:0 KB 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 ds, 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 cocould be repetitions among the given pairs.

 

Output

The output for each test case shoshould 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;}


The Code does not have an AC, and is displayed in Judge queue on both the ultraviolet A and virtual OJ.

It means it is speechless. After waiting for a long time, the virtual OJ displays judging Error 2. A faint sorrow ..


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.