题目链接: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. winform如何不卡界面

    快速阅读 如何在winform程序中,让界面不再卡死. 关于委托和AsyncCallback的使用. 界面卡死的原因是因为耗时任务的计算占用了主线程,导致主界面没有办法进行其它操作,比如拖动.造成界面 ...

  2. win10下Python安装pycrypto报错

    错误一:  error: Microsoft Visual C++ 14.0 is required. 解决办法: 下载Visual C++2017安装包,下载链接:Visual C++ 2017 安 ...

  3. html5的datalist元素详解

    html5的datalist元素详解 一.总结 一句话总结: datalist元素配合input元素可以出现有提示选择作用的选框效果,还是相对比较简便好用的 1.optgroup元素是干嘛的? opt ...

  4. 如何登陆Tomcat的控制台

    当我们成功安装启动Tomcat服务后,在浏览器输入http://localhost:8080(8080是Tomcat的默认端口,可自行修改)回车 右上角可以看到三个控制台:Server Status. ...

  5. springboot前端传参date类型后台处理方式

    转载:https://blog.csdn.net/xiangluer/article/details/81913137?utm_source=copy 参考如下博客: https://www.jian ...

  6. Windows环境下的安装gcc(c语言环境)

    Windows 具有良好的界面和丰富的工具,所以目前 linux 开发的流程是, windows 下完成编码工作, linux 上实现编译工作. 为了提高工作效率,有必要在 windows 环境下搭建 ...

  7. vue报错:There are multiple modules with names that only differ in casing.

    今天写项目时,遇到报错信息如下: 经过多次排除及参考网上文章,最后找到问题所在 排查原因:1 .在引用组件时,路径大小写不对也会造成此报错,看例子:错误写法: 正确写法: 2.在组件使用vuex时,引 ...

  8. Gradle: 一个诡异的问题(ERROR: Failed to parse XML AndroidManifest.xml ParseError at [row,col]:[5,5] Message: expected start or end tag)

    今天同事说他下了一个老版本的AS项目死活编不过,我心想不就是一个项目么,编不过要么就是代码有问题,要么就是依赖库不完整这能有什么问题,于是自己在自己电脑试了下,结果自己也中招了: 乍一看这个错误,说是 ...

  9. python的xpinyin模块:汉字转拼音

                            pypinyin 1.安装 pip install pypinyin 2.使用方法 >>> from pypinyin import ...

  10. HBase在特征工程中的应用

    前言HBase是一款分布式的NoSQL DB,可以轻松扩展存储和读写能力. 主要特性有: 按某精确的key获取对应的value(Get) 通过前缀匹配一段相邻的数据(Scan) 多版本 动态列 服务端 ...