(并查集)The Suspects --POJ --1611
链接:
http://poj.org/problem?id=1611
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/B
代码:
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #define N 30005
- int a[N];
- int n, m;
- int Find(int x)
- {
- if(a[x]!=x)
- a[x] = Find(a[x]);
- return a[x];
- }
- int main()
- {
- while(scanf("%d%d", &n, &m), n+m)
- {
- int p, px, py, s, x, y;
- for(int i=; i<=n; i++)
- a[i] = i;
- for(int i=; i<m; i++)
- {
- scanf("%d%d", &s, &x);
- for(int j=; j<s; j++)
- {
- scanf("%d", &y);
- px = Find(x);
- py = Find(y);
- if(px!=py)
- a[py] = px;
- }
- }
- int sum=;
- p = Find();
- for(int i=; i<n; i++)
- if(Find(i)==p)
- sum++;
- printf("%d\n", sum);
- }
- return ;
- }
(并查集)The Suspects --POJ --1611的更多相关文章
- C - The Suspects POJ - 1611(并查集)
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
- B - The Suspects -poj 1611
病毒扩散问题,SARS病毒最初感染了一个人就是0号可疑体,现在有N个学生,和M个团队,只要团队里面有一个是可疑体,那么整个团队都是可疑体,问最终有多少个人需要隔离... 再简单不过的并查集,只需要不断 ...
- The Suspects POJ 1611
The Suspects Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, w ...
- 并查集判树 poj 1308
例题: poj 1308 题目大意比较简单,对任意两个点,有且仅有一条道路,也就是一棵树. 题解:一棵树中,肯定是不能有环的,而且只能由一个根节点.(没认真读题,只知道在那里判环....),所以这个题 ...
- kuangbin 并查集
A : Wireless Network POJ - 2236 题意:并查集,可以有查询和修复操作 题解:并查集 #include<iostream> #include<cstdi ...
- [kuangbin带你飞]专题五 并查集
并查集的介绍可以看下https://www.cnblogs.com/jkzr/p/10290488.html A - Wireless Network POJ - 2236 An earthquake ...
- 并查集 (poj 1611 The Suspects)
原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...
- [并查集] POJ 1611 The Suspects
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 35206 Accepted: 17097 De ...
- poj 1611:The Suspects(并查集,经典题)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21472 Accepted: 10393 De ...
随机推荐
- 使用HttpURLConnection时遇到的资源未释放的问题
http://blog.sina.com.cn/s/blog_56beadc60100j9zu.html 今天自己写了一个压力测试的小程序,同时启100个线程,每个线程都串行地访问应用服务器上的一个j ...
- Haskell语言学习笔记(42)Bifunctor
Bifunctor class Bifunctor p where bimap :: (a -> b) -> (c -> d) -> p a c -> p b d bim ...
- autoface
Autofac 依赖注入框架 使用 2015-08-02 10:20 by jiangys, 36262 阅读, 4 评论, 收藏, 编辑 简介 Autofac是一款IOC框架,比较于其他的IOC框架 ...
- 全面解析PHP面向对象的三大特征
PHP面向对象的三大特征: 继承,封装,多态 一.继承 1.如何实现继承? 给子类使用extends关键字,让子类继承父类: class Student extends Person{} 2.实现继承 ...
- bash: ifconfig: command not found 问题解决
ifconfig使用出现问题了?竟然提示找不到~~于是百度~~ [flymouse@localhost /]$ ifconfig 提示:“bash: ifconfig: command not fou ...
- 基元线程同步构造之信号量(Semaphore)
信号量(semaphore)不过是由内核维护的 int32变量而已,(说通俗点就是好比一个线程容器里面允许执行的线程数,0计数就是允许执行的0个线程数,1就是允许执行的1个线程数,2就是允许执行的2个 ...
- Fb,tw等emoji相关
最近处理fb emoji,查了下相关的资料.记录于此 twitter blog 关于:https://blog.twitter.com/developer/en_us/a/2014/open-sou ...
- Anaconda中python加入环境变量
1.我的电脑---高级系统设置 2.选中环境变量,保存. 3.在系统环境变量PATH中,加入Anaconda3及Script路径加入其中 4.测试python
- 安装RabbitMq-----windows
在官网download我们所需要的版本,安装rabbitMq需要erlang支持 rabbitMq :http://www.rabbitmq.com/download.html erlang :ht ...
- java重载(实现同一方法名,不同参数)
背景: 前几天写连接数据库时,因为要执行sql,有的是指向得到所有的执行结果,有的是想根据执行结果获得某一个字段的结果.这时我想通过同一个方法名,不同的参数,获得不同的结果.结果发现java的方法竟 ...