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
分析
WUSTOJ 1319: 球(Java)并查集的更多相关文章
- java 并查集
并查集代码 并查集优化⼀ 并查集优化⼆ 实战题⽬目1. https://leetcode.com/problems/number-of-islands/2. https://leetcode.com/ ...
- Java 并查集Union Find
对于一组数据,主要支持两种动作: union isConnected public interface UF { int getSize(); boolean isConnected(int p,in ...
- java——并查集 UnionFind
时间复杂度: O(log*n),近乎是O(1)级别的 UnionFind 接口: public interface UF { int getSize(); boolean isConnected(in ...
- WUSTOJ 1346: DARK SOULS(Java)并查集
题目链接:1346: DARK SOULS 并查集系列:WUSTOJ 1319: 球(Java)并查集 Description CQ最近在玩一款游戏:DARK SOULS,这是一款以高难度闻名的硬派动 ...
- 并查集(Java实现)
(最好在电脑下浏览本篇博客...手机上看代码不方便) 当时学的时候看的一本印度的数据结构书(好像是..有点忘了..反正跟同学们看的都不一样...)...里面把本文提到的所有情况都提到了,我这里只是重复 ...
- 并查集的Java实现
Java实现并查集,合并时采用路径压缩算法. 如果合并时使用循环修改的方法,一次合并的时间复杂度就为N,无法接受 public class Union { public int[] id;//对应索引 ...
- 并查集---java模板
并查集,在一些有N个元素的集合应用问题中,我们通常是在开始时让每个元素构成一个单元素的集合,然后按一定顺序将属于同一组的元素所在的集合合并,其间要反复查找一个元素在哪个集合中.这一类问题近几年来反复出 ...
- HYSBZ - 1050(旅行comf 并查集Java实现)
HYSBZ - 1050(旅行comf Java实现) 原题地址 解法:枚举每一条边,对于这条边,我们需要找到集合中和其值相差最小的最大边,这个集合是指与包括i边在内的ST联通集.对于这一要求,我们只 ...
- 并查集(不相交集合)详解与java实现
目录 认识并查集 并查集解析 基本思想 如何查看a,b是否在一个集合? a,b合并,究竟是a的祖先合并在b的祖先上,还是b的祖先合并在a上? 其他路径压缩? 代码实现 结语 @(文章目录) 认识并查集 ...
随机推荐
- java 静态数组 和非静态数组的区别
区别:1,数组创建时间不同,静态的是一定义出来就创建了,动态的则是定义时不创建,使用时才创建,一定意义上节省了内存空间.2,使用场景不同,一开始就知道数组长度的使用静态初始化,反之,动态初始化. 静态 ...
- ConsoleWebsocketServer服务端和ConsoleWebsocketClient客户端
本文是简述了Websocket的服务端和客户端的实时通讯过程,Websocket的服务端和客户端的具体使用使用了2种Websocket的服务端和2种客户端. 以下代码使用的是Visual Studio ...
- crontab 使用日期时间命名重定向文件
使用月份命名 0 12 * * * sh /tmp/test.sh >> "/tmp/$(date +"\%Y-\%m").log" 2>&a ...
- MYSQL双主模式,触发器(trigger)不可见问题
MYSQL版本信息: Your MySQL connection id is 71851 Server version: 5.7.24-log MySQL Community Server (GPL) ...
- PHP7 serialize_precision 配置不当导致 json_encode() 浮点小数溢出错误
https://blog.csdn.net/moliyiran/article/details/81179825 感谢 @地狱星星:原因已找到, 该现象只出现在PHP 7.1+版本上建议使用默认值 s ...
- iptables nat表配置
- linux安装6.5.3版本elastic search
到官网https://www.elastic.co/cn/downloads/elasticsearch下载压缩包,目前最新的版本是7.3.2,我想下6.5.3,点击下面的past release链接 ...
- ES6深入浅出-6 ES 6 模块-2.babel webpack parcel
https://babeljs.io/ 复制到命令行执行 提示一个警告.缺少package.json这个文件 npm init -t ls 然后看到了生成了package.json这个文件. 然后再去 ...
- Python记录-python执行shell命令
# coding=UTF-8 import os def distcp(): nncheck = os.system('lsof -i:8020') dncheck = os.system('lsof ...
- delphi 多线程定时执行程序如何写
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...