链接:

http://poj.org/problem?id=1611

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/B

代码:

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. #define N 30005
  6.  
  7. int a[N];
  8. int n, m;
  9.  
  10. int Find(int x)
  11. {
  12. if(a[x]!=x)
  13. a[x] = Find(a[x]);
  14. return a[x];
  15. }
  16.  
  17. int main()
  18. {
  19.  
  20. while(scanf("%d%d", &n, &m), n+m)
  21. {
  22. int p, px, py, s, x, y;
  23.  
  24. for(int i=; i<=n; i++)
  25. a[i] = i;
  26.  
  27. for(int i=; i<m; i++)
  28. {
  29. scanf("%d%d", &s, &x);
  30.  
  31. for(int j=; j<s; j++)
  32. {
  33. scanf("%d", &y);
  34.  
  35. px = Find(x);
  36. py = Find(y);
  37. if(px!=py)
  38. a[py] = px;
  39. }
  40. }
  41. int sum=;
  42. p = Find();
  43.  
  44. for(int i=; i<n; i++)
  45. if(Find(i)==p)
  46. sum++;
  47.  
  48. printf("%d\n", sum);
  49.  
  50. }
  51. return ;
  52. }

(并查集)The Suspects --POJ --1611的更多相关文章

  1. C - The Suspects POJ - 1611(并查集)

    Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...

  2. B - The Suspects -poj 1611

    病毒扩散问题,SARS病毒最初感染了一个人就是0号可疑体,现在有N个学生,和M个团队,只要团队里面有一个是可疑体,那么整个团队都是可疑体,问最终有多少个人需要隔离... 再简单不过的并查集,只需要不断 ...

  3. The Suspects POJ 1611

    The Suspects Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, w ...

  4. 并查集判树 poj 1308

    例题: poj 1308 题目大意比较简单,对任意两个点,有且仅有一条道路,也就是一棵树. 题解:一棵树中,肯定是不能有环的,而且只能由一个根节点.(没认真读题,只知道在那里判环....),所以这个题 ...

  5. kuangbin 并查集

    A : Wireless Network  POJ - 2236 题意:并查集,可以有查询和修复操作 题解:并查集 #include<iostream> #include<cstdi ...

  6. [kuangbin带你飞]专题五 并查集

    并查集的介绍可以看下https://www.cnblogs.com/jkzr/p/10290488.html A - Wireless Network POJ - 2236 An earthquake ...

  7. 并查集 (poj 1611 The Suspects)

    原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...

  8. [并查集] POJ 1611 The Suspects

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 35206   Accepted: 17097 De ...

  9. poj 1611:The Suspects(并查集,经典题)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 De ...

随机推荐

  1. 使用HttpURLConnection时遇到的资源未释放的问题

    http://blog.sina.com.cn/s/blog_56beadc60100j9zu.html 今天自己写了一个压力测试的小程序,同时启100个线程,每个线程都串行地访问应用服务器上的一个j ...

  2. Haskell语言学习笔记(42)Bifunctor

    Bifunctor class Bifunctor p where bimap :: (a -> b) -> (c -> d) -> p a c -> p b d bim ...

  3. autoface

    Autofac 依赖注入框架 使用 2015-08-02 10:20 by jiangys, 36262 阅读, 4 评论, 收藏, 编辑 简介 Autofac是一款IOC框架,比较于其他的IOC框架 ...

  4. 全面解析PHP面向对象的三大特征

    PHP面向对象的三大特征: 继承,封装,多态 一.继承 1.如何实现继承? 给子类使用extends关键字,让子类继承父类: class Student extends Person{} 2.实现继承 ...

  5. bash: ifconfig: command not found 问题解决

    ifconfig使用出现问题了?竟然提示找不到~~于是百度~~ [flymouse@localhost /]$ ifconfig 提示:“bash: ifconfig: command not fou ...

  6. 基元线程同步构造之信号量(Semaphore)

    信号量(semaphore)不过是由内核维护的 int32变量而已,(说通俗点就是好比一个线程容器里面允许执行的线程数,0计数就是允许执行的0个线程数,1就是允许执行的1个线程数,2就是允许执行的2个 ...

  7. Fb,tw等emoji相关

    最近处理fb  emoji,查了下相关的资料.记录于此 twitter blog 关于:https://blog.twitter.com/developer/en_us/a/2014/open-sou ...

  8. Anaconda中python加入环境变量

    1.我的电脑---高级系统设置 2.选中环境变量,保存. 3.在系统环境变量PATH中,加入Anaconda3及Script路径加入其中 4.测试python

  9. 安装RabbitMq-----windows

    在官网download我们所需要的版本,安装rabbitMq需要erlang支持 rabbitMq :http://www.rabbitmq.com/download.html erlang  :ht ...

  10. java重载(实现同一方法名,不同参数)

    背景:  前几天写连接数据库时,因为要执行sql,有的是指向得到所有的执行结果,有的是想根据执行结果获得某一个字段的结果.这时我想通过同一个方法名,不同的参数,获得不同的结果.结果发现java的方法竟 ...