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 ...
随机推荐
- 解决Centos 7 dhcp服务器-no subnet declaration for start (no IPV4 addresses.)
上面的配置是hyper-v 安装的 centos 7.0 安装dhcp 服务器的方法是 yum install dhcpd 在安装和配置好后,运行的时候出现错误 错误提示如下: no subnet d ...
- Unity3d该物业(Attributes)整理
http://blog.sina.com.cn/s/blog_5b6cb9500101857b.html Attributes属性属于U3D的RunTimeClass,所以加上下面的命名空间是必须的了 ...
- HDU 4391 Paint The Wall 段树(水
意甲冠军: 特定n多头排列.m操作 以下是各点的颜色 以下m一种操纵: 1 l r col 染色 2 l r col 问间隔col色点 == 通的操作+区间内最大最小颜色数的优化,感觉非常不科学... ...
- 综合第一篇文章(带钩Quora)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc4MzAyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- 【Android基础】listview控件的使用(2)-------继承自ListActivity的普通listview
由于listview在android控件中的重要性,所以android为我们直接封装了一个类ListviewActivity,直接将listview封装在了activity之中,在本篇中,我将介绍在L ...
- CentOS-6.5-x86_64 最小化安装后,怎样安装 man 程序?
CentOS-6.5-x86_64 最小化安装后.怎样安装man 程序? CentOS-6.5-x86_64 最小化安装后,没有man 程序,没它还真的不方便. man 是 manual(手冊)的意思 ...
- C# WinForm 拖动无边框窗体 改变无边框窗体尺寸
经常遇到这种情况.窗体的边框去掉了.然后种种问题就出来了:不能拖动.不能改变窗体大小.不能......当然.肯定有解决方案滴*^_^*今天的目标就是:可以直接拖动没有边框的窗体.可以直接拉拽窗体改变其 ...
- IIS7启用静态压缩
IIS7启用压缩的操作如下图: 默认情况下IIS7是启用GZip压缩的,但是有时候我们会发现谁然启用了压缩但是一些js和css文件仍然没有被压缩,这个时候需要修改一下IIS 的配置文件: 在C:\Wi ...
- 使用AppCompat_v7 21.0.0d的几个兼容问题
1.实现新的ActionBarDrawerToggle动画 ActionBarDrawerToggle使用最新的AppCompat_v7 21会出现一个非常帅的动画.使用方式在Androidstudi ...
- 更改IOS于UISearchBar撤消button底、搜索输入文本框背景中的内容和UISearchBar底
转载请标明出处:http://blog.csdn.net/android_ls/article/details/39993433 測试的手机IOS系统版本为:6.1.3,实现过程例如以下: 1.加入U ...