题目描述

Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others. 
In the Not-Spreading-Your-Sickness University (NSYSU), there are many student groups. Students in the same group intercommunicate with each other frequently, and a student may join several groups. To prevent the possible transmissions of SARS, the NSYSU collects the member lists of all student groups, and makes the following rule in their standard operation procedure (SOP). 
Once a member in a group is a suspect, all members in the group are suspects. 
However, they find that it is not easy to identify all the suspects when a student is recognized as a suspect. Your job is to write a program which finds all the suspects.

输入

The input file contains several cases. Each test case begins with two integers n and m in a line, where n is the number of students, and m is the number of groups. You may assume that 0 < n <= 30000 and 0 <= m <= 500. Every student is numbered by a unique integer between 0 and n−1, and initially student 0 is recognized as a suspect in all the cases. This line is followed by m member lists of the groups, one line per group. Each line begins with an integer k by itself representing the number of members in the group. Following the number of members, there are k integers representing the students in this group. All the integers in a line are separated by at least one space.

A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.

输出

For each case, output the number of suspects in one line.

样例输入

100 4
2 1 2
5 10 13 11 12 14
2 0 1
2 99 2
200 2
1 5
5 1 2 3 4 5
1 0
0 0

样例输出

4
1
1
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <string>
 5 using namespace std;
 6 int a[30010];
 7 void cmp()
 8  {
 9     int i;
10     for(i=0;i<30005;i++)
11        {
12         a[i]=i;
13        }
14  }
15  int root(int x)
16  {
17     while(a[x]!=x)
18         x=a[x];
19     return x;
20  }
21  void build(int x,int y)
22  {
23     int i,j;
24     i=root(x);
25     j=root(y);
26     if(i!=j)
27     {
28         if(i==0)
29            a[j]=i;
30         else a[i]=j;
31     }
32  }
33  int main()
34  {
35     int n,m,k,p,q,i,j,first,next;
36     while(cin>>n>>m)
37     {  if(n==0&&m==0) break;
38         cmp();
39         int ii=m;
40         while(m--)
41         {
42             cin>>k>>first;
43             for(i=1;i<k;i++)
44                 {
45                     cin>>next;
46                     build(first,next);
47                 }
48         }
49         q=0;
50         if(ii==0) cout<<"1"<<endl;
51         else
52         {
53            for(i=0;i<n;i++)
54            {
55               if(!root(a[i]))q++;
56            }
57            cout<<q<<endl;
58         }
59     }
60     return 0;
61  } 

转载于:https://www.cnblogs.com/wangmengmeng/p/5271893.html

NYNU_省赛选拔题(10)相关推荐

  1. 【蓝桥杯省赛真题10】Scratch考试成绩 少儿编程scratch蓝桥杯省赛真题讲解

    目录 scratch考试成绩 一.题目要求 编程实现 二.案例分析 1.角色分析 2.背景分析 3.前期准备 三.解题思路 1.Jamie 2.Kai 四.程序编写 1.Jamie 2.Kai 五.考 ...

  2. 蓝桥杯大学JAVA题型_蓝桥杯 2020年省赛真题 10月第二场 (Java 大学B组)

    我是C组的,不过对比一下题目录,大致上也只有三两题的不同 就过程而言我觉得我是爆炸的,当然,就结果而言也是 先挂,自闭会 #A 门牌制作 本题总分:5 分 问题描述 小蓝要为一条街的住户制作门牌号. ...

  3. 历届蓝桥杯Scratch编程国赛 初级 中级 青少年编程比赛国赛真题解析【持续更新 已更新至27题】

    历届蓝桥杯国赛真题 第十三界.十二届.十一届等历届青少年蓝桥杯Scratch编程比赛国赛真题解析 国赛真题01-河马带球[试看] [蓝桥杯国赛真题01]Scratch河马带球 少儿编程蓝桥杯Scrat ...

  4. 历届蓝桥杯Scratch编程省赛 初级 中级 青少年编程比赛省赛真题解析【持续更新 已更新至35题】

    历届蓝桥杯scratch省赛真题 历年蓝桥杯Scratch编程比赛省赛真题详细解析 省赛真题35-水面倒影 [蓝桥杯省赛真题35]Scratch水面倒影 少儿编程scratch编程蓝桥杯省赛真题讲解_ ...

  5. 2019年 第10届 蓝桥杯 Java B组 省赛真题详解及总结

    蓝桥杯 Java B组 省赛真题详解及小结汇总[2013年(第4届)~2020年(第11届)] 注意:部分代码及程序 源自 蓝桥杯 官网视频(历年真题解析) 郑未老师. 2013年 第04届 蓝桥杯 ...

  6. 小猫打螃蟹-第10届蓝桥杯Scratch省赛真题第2题

    [导读]:超平老师计划推出Scratch蓝桥杯真题解析100讲,这是超平老师解读Scratch蓝桥真题系列的第67讲. 第10届蓝桥杯青少年组省赛于2019年3月24日举行,形式为线下考试.Scrat ...

  7. 捉迷藏之二-第10届蓝桥杯Scratch国赛真题第6题程序2

    本文同步发表于"超平的编程课"公众号,更多教程,可移步至公众号. [导读]:超平老师计划推出Scratch蓝桥杯真题解析100讲,这是超平老师解读Scratch蓝桥真题系列的第15 ...

  8. 击鼓游戏-第10届蓝桥杯Scratch省赛真题第7题

    [导读]:超平老师计划推出Scratch蓝桥杯真题解析100讲,这是超平老师解读Scratch蓝桥真题系列的第62讲. 第10届蓝桥杯青少年组省赛于2019年3月24日举行,形式为线下考试.Scrat ...

  9. 自动驾驶-第10届蓝桥杯Scratch省赛真题第5题

    [导读]:超平老师计划推出Scratch蓝桥杯真题解析100讲,这是超平老师解读Scratch蓝桥真题系列的第64讲. 第10届蓝桥杯青少年组省赛于2019年3月24日举行,形式为线下考试.Scrat ...

最新文章

  1. java 假设当前时间_java——推断日期是否在今天之前
  2. 电脑知识--Windows一片
  3. 事务嵌套问题_注意Spring事务这一点,避免出现大事务
  4. 这就是即将发布的苹果刘海屏MacBook Pro样机?
  5. bs后端开发语言_哪种编程语言适合后端开发?Java和PHP的区别在哪?
  6. linux下目标文件的类型6,Linux下文件类型
  7. 数据结构排序系列详解之七 归并排序
  8. Ableton Live 11 Suite for Mac(专业音乐创作软件)
  9. 【TWVRP】基于matlab改进的遗传算法求解带时间窗约束多卫星任务规划问题【含Matlab源码 1774期】
  10. 【BZOJ1150】数据备份(堆/优先队列)
  11. html5制作旋转正方体,html5—旋转立方体
  12. 格式化的硬盘能恢复吗 硬盘格式化以后能恢复吗
  13. 杂谈 跟编程无关的事情11
  14. SpringBoot FlyWay报错:Detected applied migration not resolved locally:
  15. 网易收购《底特律》《暴雨》开发商继续走向全球化
  16. 新零售连锁店系统为何这么火?
  17. 横河dcs系统配有服务器吗,横河DCS常见问题的解答 转贴
  18. QT 带 进度条 解压缩文件方法 - QuaZip
  19. Ray----Tune(6):Tune 的实例(一)
  20. python和Anaconda 安装gdal和osr

热门文章

  1. 配置机器学习训练环境太麻烦?开源工具Parris说一键就搞定
  2. 百度DuerOS与高通合推手机语音交互解决方案,谁会欢喜谁要愁?
  3. Commons Configuration之一简介
  4. web app页面要求
  5. Setting property 'source' to 'org.eclipse.jst.jee.
  6. opengl 坐标的基本变换
  7. 使用Apache的ab工具进行压力测试
  8. Windows Server入门系列之三 硬盘分区
  9. WebCruiser Web Security Scanner
  10. UWP 保存用户设置