题目链接: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. TCP粘包拆包问题分析及应对方案

    粘包拆包问题是处于网络比较底层的问题,在数据链路层.网络层以及传输层都有可能发生.我们日常的网络应用开发大都在传输层进行,由于UDP有消息保护边界,不会发生粘包拆包问题,因此粘包拆包问题只发生在TCP ...

  2. JavaWeb之Tomcat(1) —— Tomcat的目录结构

    1. bin 文件夹 存放Tomcat的可执行文件 (1) startup.bat 文件,启动Tomcat服务的批处理文件. (2) shutdown.bat 文件,结束Tomcat服务的批处理文件. ...

  3. T-MAX组--项目冲刺(第七天)

    THE SEVENTH DAY 项目相关 作业相关 具体描述 所属班级 2019秋福大软件工程实践Z班 作业要求 团队作业第五次-项目冲刺 作业正文 T-MAX组--项目冲刺(第七天) 团队名称 T- ...

  4. Python自动化测试常用库

    基本库: sys 程序和Python解析器的交互 os 启动新进程:操作文件和目录 re 正则表达式,字符串匹配 string 基本字符串操作 inspect 提供自省和反射功能 importlib ...

  5. ORACLE AUDIT

    Oracle 作者:Davis_itpub 时间:2018-06-27 16:28:39  61  0 审计(Audit)用于监视用户所执行的数据库操作,并且Oracle 会将审计跟踪结果存放到OS ...

  6. openwrt共享打印机需要安装哪几个文件

    opkg updateopkg install luci-app-p910ndopkg install kmod-usb-printer

  7. TextBox光标定位到文本末尾

    private void RichTextBox1_TextChanged(object sender, EventArgs e) { this.richTextBox1.Select(richTex ...

  8. [转]java生成 excel 并导出文件

    原文:https://blog.csdn.net/xunwei0303/article/details/53213130 目前,比较常用的实现Java导入.导出Excel的技术有两种Jakarta P ...

  9. Docker Error response from daemon: driver failed programming external connectivity on endpoint webserver

    按照官网的配置, https://docs.docker.com/docker-for-windows/ 当执行到第 5 步时 如果当前你的电脑 80 端口已经被别的程序占用,运行以上命令就会报错,报 ...

  10. git git push某一次的commit记录

    $ git push <remote name> <commit hash>:<remote branch name> # Example:$ git push o ...