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

【Accepted】

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include <string>
  6. using namespace std;
  7. const int maxn=3e4+;
  8. int fa[maxn];
  9. int n,m;
  10. int a[maxn];
  11.  
  12. void init()
  13. {
  14. for(int i=;i<n;i++)
  15. {
  16. fa[i]=i;
  17. }
  18. }
  19. int find(int x)
  20. {
  21. return x==fa[x]?x:fa[x]=find(fa[x]);
  22. }
  23.  
  24. void mix(int x,int y)
  25. {
  26. int fx=find(x);
  27. int fy=find(y);
  28. if(fx!=fy)
  29. {
  30. fa[fx]=fy;
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. while(~scanf("%d%d",&n,&m))
  37. {
  38. if(n==&&m==)
  39. {
  40. break;
  41. }
  42. init();
  43. for(int i=;i<m;i++)
  44. {
  45. int k;
  46. scanf("%d",&k);
  47. if(k>=)
  48. {
  49. scanf("%d",&a[]);
  50. for(int j=;j<k;j++)
  51. {
  52. scanf("%d",&a[j]);
  53. mix(a[],a[j]);
  54. }
  55. }
  56. }
  57. int sum=;
  58. for(int i=;i<n;i++)
  59. {
  60. if(find(i)==fa[])
  61. {
  62. sum++;
  63. }
  64. }
  65. printf("%d\n",sum);
  66. }
  67. return ;
  68. }

【不太明白】

为啥find(i)==fa[0]能A,fa[i]==fa[0]就是WA。find(0)一定等于fa[0]?

【裸的并查集】POJ 1611 The Suspects的更多相关文章

  1. [并查集] POJ 1611 The Suspects

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

  2. 并查集 (poj 1611 The Suspects)

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

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

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

  4. POJ 1611 The Suspects(并查集,简单)

    为什么ACM的题意都这么难懂,就不能说的直白点吗?还能不能好好的一起刷题了? 题意:你需要建一个n的并查集,有m个集合,最后要输出包含0的那个集合的元素的个数. 这是简单并查集应用,所以直接看代码吧! ...

  5. POJ 1611 The Suspects (并查集)

    The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...

  6. poj 1611 The Suspects(并查集)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21598   Accepted: 10461 De ...

  7. poj 1611 The Suspects(并查集输出集合个数)

    Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, wa ...

  8. poj 1611 The Suspects 并查集变形题目

    The Suspects   Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 20596   Accepted: 9998 D ...

  9. poj 1611 The Suspects(第一道并查集)

    题意: 有N个学生,编号为0-n-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染, 并且这些人如果还参加了别的社团,他所在的社团照样全部感染,社团个数为m,求感染的人数. 输入: n代表人 ...

  10. POJ 1611 The Suspects (并查集+数组记录子孙个数 )

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 24134   Accepted: 11787 De ...

随机推荐

  1. IOS应用开发版本控制工具之Versions使用,iosversions

    Versions版本控制工具破解版(Versions.zip)下载请见本博文附件.下载后在MAC安装完以后,图标是莲花状.见下图: 双击运行如下图:    点击Repository,连接SVN服务器R ...

  2. 438 Find All Anagrams in a String 找出字符串中所有的变位词

    详见:https://leetcode.com/problems/find-all-anagrams-in-a-string/description/ C++: class Solution { pu ...

  3. Hibernate配置(外部配置文件方式)

    配置Hibernate有2种方式,本文讲的是通过外部配置文件配置的方式 Hibernate核心配置文件 <?xml version='1.0' encoding='UTF-8'?> < ...

  4. ssm基础配置

    1.导包 <dependencies> <dependency> <groupId>org.springframework</groupId> < ...

  5. 将call/apply方法应用于其他对象上的几种方法

    在处理类数组中,发现了两种将数组方法应用于类数组的方法,现将call/apply的常用方式总结一下. 一.当做函数调用 function print_vars(var1,var2){ console. ...

  6. (Nginx+Apache)实现反向代理与负载均衡

    反向代理负载均衡 使用代理服务器可以将请求转发给内部的Web服务器,使用这种加速模式显然可以提升静态网页的访问速度.因此也可以考虑使用这种技术,让代理服务器将请求均匀转发给多台内部Web服务器之一上, ...

  7. CentOS7 Install Shipyard

    # 采集木jj 原文:http://www.cnblogs.com/caoguo/p/5735189.html # CentOS7 Install Shipyard# yum install dock ...

  8. MFC_VS清理器

    VS清理器 界面 工程目录 列表控件ID改名IDC_FILELIST 绑定变量m_FileList 属性设置Accept Files 设置True 成员添加 // 用于保存待遍历的目录 vector& ...

  9. https://quotefancy.com/ 经典句子(英语) 真是特别好~

    https://quotefancy.com/ 经典句子(英语)

  10. 【Hadoop】一、分布式数据库HBase简介

    1.分布式数据库特点   说到数据库,我们最熟悉的是类似于mysql这样的关系型数据库,称为RDBMS.关系型数据库作为一种数据存储和数据检索的关键技术,它支持SQL语言的结构化查询,但是它天生不是为 ...