NYNU_省赛选拔题(10)
题目描述
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
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int a[];
void cmp()
{
int i;
for(i=;i<;i++)
{
a[i]=i;
}
}
int root(int x)
{
while(a[x]!=x)
x=a[x];
return x;
}
void build(int x,int y)
{
int i,j;
i=root(x);
j=root(y);
if(i!=j)
{
if(i==)
a[j]=i;
else a[i]=j;
}
}
int main()
{
int n,m,k,p,q,i,j,first,next;
while(cin>>n>>m)
{ if(n==&&m==) break;
cmp();
int ii=m;
while(m--)
{
cin>>k>>first;
for(i=;i<k;i++)
{
cin>>next;
build(first,next);
}
}
q=;
if(ii==) cout<<""<<endl;
else
{
for(i=;i<n;i++)
{
if(!root(a[i]))q++;
}
cout<<q<<endl;
}
}
return ;
}
NYNU_省赛选拔题(10)的更多相关文章
- NYNU_省赛选拔题(7)
题目描述 In computer science, a binary tree is a tree data structure in which each node has at most two ...
- NYNU_省赛选拔题(5)
题目描述 P 的一家要出去旅游,买了当地的地图,发现各地分别由各个景点,若 P 想使家人分队去景点,尽快到达各个景点(必须所有景点),并且最终所有家人都到达 M 所在的景点. 你用程序告诉 P 最 ...
- NYNU_省赛选拔题(8)
题目描述 一天萌萌哒孟孟学长去博物馆参观,他想看到更多的东西.博物馆可以表示为N × M细胞的一个矩形区域. “.”表示为路,“*”表示为墙壁,每个墙壁上面都挂有美丽的画卷.孟孟学长可以看到与他所在位 ...
- NYNU_省赛选拔题(6)
题目描述 有一天,小米找到了一个藏宝的迷宫地图,迷宫在一个沙漠里有,迷宫里面有许多宝藏.迷宫里可能有N个藏宝地点,用1到K标记.藏宝地点之间最多有一条通路相连.标记1为迷宫的进出口. 他已经知道其中K ...
- NYNU_省赛选拔题(3)
题目描述 二叉树,若其与自己的镜像完全相同,就称其为镜像树. 是一棵镜像树:而 不是镜像树.现给你一棵二叉树,请你判断其是不是镜像树. 输入 第一行是一个整数数T,表示测试数据有多少组每组数据第一行是 ...
- 2013年省赛H题
2013年省赛H题你不能每次都快速幂算A^x,优化就是预处理,把10^9预处理成10^5和10^4.想法真的是非常巧妙啊N=100000构造两个数组,f1[N],间隔为Af2[1e4]间隔为A^N,中 ...
- 2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告
2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh ...
- HDU-5532//2015ACM/ICPC亚洲区长春站-重现赛-F - Almost Sorted Array/,哈哈,水一把区域赛的题~~
F - Almost Sorted Array Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)
2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...
随机推荐
- C++primer读书笔记9-转换和类类型
有时指定自己的类类型来表示某些类型的数据,如SmallInt,然后在为了便于计算将指定一个转换算,类类型,在某些情况下,自己主动转换为指定的类型 <1>转换操作符 operator typ ...
- Andoird实现类似iphone AssistiveTouch的控件的demo
类似Iphone Assistive Touch的控件的实现 网上也有些这方面的控件,不过貌似不怎么好用,或者是论坛需要积分下载,恰好自己在项目中有用到这种控件,就打算自己写一个,也成功实现了这种功能 ...
- Java 对象的生命周期
Java对象的生命周期 在Java中,对象的生命周期包含下面几个阶段: 1. 创建阶段(Created) 2. 应用阶段(In Use) 3. 不可见阶段(Invisib ...
- 谈谈CListCtrl 扩展风格设置方法-SetExtendedStyle和ModifyStyleEx 比較
谈谈CListCtrl 扩展风格设置方法 --------------------------------------SetExtendedStyle和ModifyStyleEx 比較 对于刚開始学习 ...
- Python 保存爬行动物捕捉网页
选址的桌面壁纸网站汽车主题: 下面的两个print打开调试期间 #print tag #print attrs #!/usr/bin/env python import re import urlli ...
- 获取activity的根视图
Activity的根视图是什么? Activity所谓的根视图,就是Activity的最底层的View,也就是在Acitivty创建的时候setContentView的时候传入的View. 如何获取到 ...
- Make a dent in the universe
李自成<一个数学家平反>.就像我第一次读同一,我感到鼓舞的野心文."野心是世界的驱动力的最好的结果几乎所有的工作. " 心野心是要留下点什么在自己身后的永恒价值 在这个 ...
- maven插件的生命周期的详细说明(两)
插件配置 定义解释:插件目标 当我们了解了maven插件之后.我们发现假设为每个功能编写一个独立的插件显然是不可取的,由于这些任务背后有非常多能够复用的代码.因此,把这些功能聚集在一个插件里,每个功能 ...
- 谈话节目APE系列:如何成为技术达人
作为一个程序猿,总有消退的前辈.或更年轻的同行.牛逼的人总是羡慕. 让我们搞自己痛苦的日子 BUG .头发很快结束了抓,人们扫两.修改一行代码.问题得以克服:例如,他们自己开发的十年,少付 10K , ...
- php中国的垃圾问题
header这条线加,这是解决中国乱码的问题. 版权声明:本文博主原创文章,博客,未经同意不得转载.