WUSTOJ 1319: 球(Java)并查集
题目链接:1319: 球
参考:wustoj 1319 球—wust_tanyao,并查集
并查集系列:WUSTOJ 1346: DARK SOULS(Java)并查集
Description
Icy is a lonely boy. He was so boring these days. So he started to play a game himself. First, he took a heap of balls with many different colors. ( One ball with only one color ) Then he repeated to pick two balls and put them back. Each time the two balls he chose is of the same color. After M times, Icy was too boring to fall asleep.
Now, a boring people wanna ask you a very easy question: how many different colors are there in the original heap at most ?
Input
The first line contains one integer T indicating the number of test cases.
For each test case, the first line contains two integer numbers N and M (0 <= N,M<= 10000) that represents the total number of balls and the number of times Icy took balls.Balls are numbered from 1 to N.Each of the following M lines contains two integer numbers A and B (1 <= A, B <= N). It means that Icy picked ball A and ball B.
一共有N个球,每个球只有一种颜色,每次取出颜色相同的两个球,然后放回去,取M次,问最多有多少种颜色?
Output
For each test case, output an integer that satisfies the problem description.
Sample Input
2
3 3
1 2
2 3
1 3
3 1
1 2
Sample Output
1
2