POJ_1611_The Suspect

The Suspects

Time Limit: 1000MS   Memory Limit: 20000K
Total Submissions: 25149   Accepted: 12329

Description

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.

Input

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.

Output

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

Sample Input

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

Sample Output

4
1
1

Source

Asia Kaohsiung 2003

题解:合并集合

代码:使用并查集

#include<iostream>
using namespace std;
int father[30010];
int input[30010];
int find(int n)
{
    if(father[n]!=n)
        father[n]=find(father[n]);
    return father[n];
}
void merge(int a,int b)
{
    int x,y;
    x=find(a);
    y=find(b);
    if(x!=y)
        father[x]=y;
}
int main()
{
    int n,m,k,num;
    int i,j;
    while(1)
    {

        cin>>n>>m;
        for(i=0; i<n; i++)
            father[i]=i;
        if(n==0&&m==0)
            break;
        while(m--)
        {
            cin>>num;
            for(i=0; i<num; i++)
                cin>>input[i];
            for(i=1; i<num; i++)
                merge(input[0],input[i]);
        }
        int cnt=1;
        for(i=1; i<n; i++)
            if(find(father[0])==find(father[i]))
                cnt++;
        cout<<cnt<<endl;
    }
    return 0;
}
时间: 2024-08-01 04:43:21

POJ_1611_The Suspect的相关文章

MS SQLServer 2008数据库处于SUSPECT情况下的处理

做任何恢复操作之前,请先备份.mdf, .ndf和.ldf文件. use master go --将处于suspect状态下的数据库设置为紧急状态 alter database <DatabaseName> set emergency go --设置该数据库为单用户立即回滚模式 alter database <DatabaseName> set single_user with rollback immediate go use <DatabaseName> go -重

解决数据库SUSPECT(置疑)状态

在虚拟机中运行数据库不小心强制关机了,结果有一个重要的数据库后面加上了一个suspect的关键字,在管理器中打不开,程序也不能运行. 网上有很多分析的方法,试了一些不管用,最后用这种方法解决了,记录一下. 执行下面的代码,其中DbTest就是出问题的数据库. EXEC sp_resetstatus 'DbTest'; ALTER DATABASE DbTest SET EMERGENCY DBCC checkdb('DbTest') ALTER DATABASE DbTest SET SINGL

Take advantage of “Integrated Calling” to know whom suspect talked to

A new feature in iOS 10 is "Integrated Calling". An integrated call from Chat App like Naver LINE or Skype or FB Messenger can be answered directly from the lock screen and from the home screen when you receive it. On the iOS lock screen, you se

Database 处于Suspect状态

在物理机安装更新,重启之后,发现有一个DB处于Suspect状态,该db的Files分布在不同的Server上,我怀疑是在RemoteServer重启时,导致该DB不能访问Remote Files,于是 SQL Server 进入 Suspect状态. 查看Windows 日志报告,发现一下错误信息: The operating system returned error 53(The network path was not found.) to SQL Server during a rea

SqlServer数据库修复Suspect的问题

-- 进入maser数据库 USE masterGO -- 启用系统表更新sp_configure 'allow updates', 1GORECONFIGURE WITH OVERRIDEGO -- 关闭 c_nzz 数据库的置疑标志sp_resetstatus c_nzzGO -- sp_resetstatus 存储过程代码IF EXISTS ( SELECT * from sysobjects where name = 'sp_resetstatus' )   DROP PROCEDURE

MS SQL恢复操作已将该数据库标记为 suspect,质疑问题有效解决

需要管理员权限 USE 数据库名 GO ALTER DATABASE 数据库名 SET EMERGENCY; GO ALTER DATABASE 数据库名 SET SINGLE_USER; GO DBCC CHECKDB (数据库名, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS; GO ALTER DATABASE 数据库名 SET MULTI_USER; GO ALTER DATABASE 数据库名 SET ONLINE; G

无法打开数据库‘Data’.恢复操作已将数据库标记为SUSPECT。

假如你是通过两个文件Data.mdf和Datalog.ldf来恢复数据库时,可能会遇到以下问题 一般恢复数据时通过附加选择文件Data.mdf进行操作就ok了,问题是可能Datalog.ldf有问题,可能会出现附加数据库出错. 然后我的方法是,在数据库中新建数据库Data,然后找到 安装路径中找到C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data 两个文件Data.mdf和Data.ldf删掉,删掉一定要把数据库服务停掉,

SQL SERVER大话存储结构(5)

阅读目录(Content) 1 基本介绍 2 对数据库启动的影响 3 日志文件添加方式 4 物理结构 5 延迟日志截断原因 6 管理事务日志 本系列上一篇博文链接:SQL SERVER大话存储结构(4)_复合索引与包含索引 回到顶部(go to top) 1 基本介绍 每个数据库都具有事务日志,用于记录所有事物以及每个事物对数据库所作的操作. 日志的记录形式需要根据数据库的恢复模式来确定,数据库恢复模式有三种: 完整模式,完全记录事物日志,需要定期进行日志备份. 大容量日志模式,适用于批量操作的

CodeForce 589A Email Aliases

Email Aliases Polycarp has quite recently learned about email aliases. Of course, he used to suspect that the case of the letters doesn't matter in email addresses. He also learned that a popular mail server in Berland bmail.com ignores dots (charact