题目链接: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

分析

WUSTOJ 1319: 球(Java)并查集的更多相关文章

  1. java 并查集

    并查集代码 并查集优化⼀ 并查集优化⼆ 实战题⽬目1. https://leetcode.com/problems/number-of-islands/2. https://leetcode.com/ ...

  2. Java 并查集Union Find

    对于一组数据,主要支持两种动作: union isConnected public interface UF { int getSize(); boolean isConnected(int p,in ...

  3. java——并查集 UnionFind

    时间复杂度: O(log*n),近乎是O(1)级别的 UnionFind 接口: public interface UF { int getSize(); boolean isConnected(in ...

  4. WUSTOJ 1346: DARK SOULS(Java)并查集

    题目链接:1346: DARK SOULS 并查集系列:WUSTOJ 1319: 球(Java)并查集 Description CQ最近在玩一款游戏:DARK SOULS,这是一款以高难度闻名的硬派动 ...

  5. 并查集(Java实现)

    (最好在电脑下浏览本篇博客...手机上看代码不方便) 当时学的时候看的一本印度的数据结构书(好像是..有点忘了..反正跟同学们看的都不一样...)...里面把本文提到的所有情况都提到了,我这里只是重复 ...

  6. 并查集的Java实现

    Java实现并查集,合并时采用路径压缩算法. 如果合并时使用循环修改的方法,一次合并的时间复杂度就为N,无法接受 public class Union { public int[] id;//对应索引 ...

  7. 并查集---java模板

    并查集,在一些有N个元素的集合应用问题中,我们通常是在开始时让每个元素构成一个单元素的集合,然后按一定顺序将属于同一组的元素所在的集合合并,其间要反复查找一个元素在哪个集合中.这一类问题近几年来反复出 ...

  8. HYSBZ - 1050(旅行comf 并查集Java实现)

    HYSBZ - 1050(旅行comf Java实现) 原题地址 解法:枚举每一条边,对于这条边,我们需要找到集合中和其值相差最小的最大边,这个集合是指与包括i边在内的ST联通集.对于这一要求,我们只 ...

  9. 并查集(不相交集合)详解与java实现

    目录 认识并查集 并查集解析 基本思想 如何查看a,b是否在一个集合? a,b合并,究竟是a的祖先合并在b的祖先上,还是b的祖先合并在a上? 其他路径压缩? 代码实现 结语 @(文章目录) 认识并查集 ...

随机推荐

  1. Android 开发常用工具合集

    在 Android 开发中经常使用到的小功能,用于记录开发的那些事^_^ 1. 获取 release 和 debug 版本的 SHA1 public static String getSHA1(Con ...

  2. 小程序map地图上显示多个marker

    wxml <map id="myMap" style="width: {{mapWidth}}rpx; height: {{mapHeight}}rpx;" ...

  3. GROUP_CONCAT 将mysql多条数据合并为一条

    实现将多条数据合并为一条数据,在mysql中可以通过 GROUP_CONCAT 函数实现 上面是潇leader发我的和工作不相关的小小小需求描述,很明显是要把id和name相同的数据合并为一条,下面按 ...

  4. [Java/Reflect]使用反射机制获得一个对象的属性名和属性值

    一个辅助对象,用于给属性排序 class KeyValue implements Comparable<KeyValue>{ String key; Object value; @Over ...

  5. 005 DOM02

    在上一篇DOM的基础上,继续案例的实践. 一:案例 1.禁用文本框 <!DOCTYPE html> <html lang="en"> <head> ...

  6. 002 centos7中遇到的问题

    在关机的时候,发现输入密码之后竟然报错了,然后确认普通用户的密码没有问题.下面是处理方式. 一:问题 1.问题 当在终端执行sudo命令时,系统提示“caojun is not in the sudo ...

  7. Manning Java Persistence with Hibernate & hibernate_in_action

    Manning | Java Persistence with Hibernatehttps://www.manning.com/books/java-persistence-with-hiberna ...

  8. centos下安装ffmpeg加上fdk-aac的支持

    本文参考自:https://blog.csdn.net/jklinux/article/details/72367829 安装包可以从这里下载https://download.csdn.net/dow ...

  9. 详解 C++11 lambda表达式

    详解 C++11 lambda表达式   lambda表达式是函数式编程的基础.咱对于函数式编程也没有足够的理解,因此这里不敢胡言乱语,有兴趣的可以自己查找相关资料看下.这里只是介绍C++11中的la ...

  10. Eclipse安装中文简体语言包

    原文地址:https://blog.csdn.net/qq_41101213/article/details/84405452 方法一:1. 下载中文语言包: 1.1 打开网址:http://www. ...