题目链接: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. 在JAVA中怎么比较Double类型数据的大小

    在JAVA中怎么比较Double类型数据的大小  我来答  浏览 33044 次   3个回答 #活动# “双11”答题活动,奖励加码!最高得2000元购物礼金! pollutedair 2015- ...

  2. Windows 10 Tensorflow 2 gpu正式版安装和更新日志

    Windows 10 Tensorflow 2 gpu正式版安装和更新日志 Tensorflow 2.0.0 released on2019年10月1日星期二 Link: https://github ...

  3. centos7.6下编译安装zabbix4.0.10长期支持版

    一.安装数据库,这里使用的是percona-server5..24版本 配置如下 [root@zabbix4_clone:~]# cat /etc/my.cnf # Example MySQL con ...

  4. shell编程系列25--shell操作数据库实战之备份MySQL数据,并通过FTP将其传输到远端主机

    shell编程系列25--shell操作数据库实战之备份MySQL数据,并通过FTP将其传输到远端主机 备份mysql中的库或者表 mysqldump 常用参数详解: -u 用户名 -p 密码 -h ...

  5. C++ STL排序问题

    /* stl排序 */ #include <iostream> #include <map> #include <vector> #include <list ...

  6. 0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

    sentinel即哨兵,相比hystrix断路器而言,它的功能更丰富.hystrix仅支持熔断,当服务消费方调用提供方发现异常后,进入熔断:sentinel不仅支持异常熔断,也支持响应超时熔断,另外还 ...

  7. quasar 报错

    yarn是项目建议安装的方式,报错如下 npm 安装的项目,报错如下 情况:无论是哪种安装方式,似乎报错都出在同一个地方. 近况,还在解决中...

  8. 为什么在MySQL数据库中无法创建外键?(MyISAM和InnoDB详解)

    问题描述:为什么在MySQL数据库中不能创建外键,尝试了很多次,既没有报错,也没有显示创建成功,真实奇了怪,这是为什么呢? 问题解决:通过查找资料,每次在MySQL数据库中创建表时默认的情况是这样的: ...

  9. bladex之nacos配置

    blade.yaml #服务器配置server:  undertow:    # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程    io-threa ...

  10. 【计算机视觉】图像配准(Image Registration)

    (Source:https://blog.sicara.com/image-registration-sift-deep-learning-3c794d794b7a)  图像配准方法概述 图像配准广泛 ...