POJ 1611 The Suspects
来源:互联网 发布:广西专业技术人员网络 编辑:程序博客网 时间:2024/06/07 12:19
一直输入,直到m,n都为0才停止运行....n个人,m组数据,每组数据开头给出一个k表示后面有k个人是同一个组的,然后就是问多少个人和0有接触,间接也算
#include <iostream>
using namespace std;int a[30008],f[30008];
int find(int x){
if(f[x] == x)
return x;
else
return f[x] = find(f[x]);
}
void un(int x,int y){
int a,b;
a = find(x);
b = find(y);
f[a] = b;
}
int main(){
int n,m,k,ans=0;
while(cin>>n>>m){
if(n==0&&m==0)
break;
ans=0;
for(int i=0;i<n;i++)
f[i]=i;
while(m--){
cin>>k;
for(int i=0;i<k;i++)
cin>>a[i];
for(int i=0;i<k-1;i++)
un(a[i],a[i+1]);
}
for(int i=0;i<n;i++)
if(find(0)==find(i))
ans++;
cout<<ans<<endl;
}
}
0 0
- POJ 1611 The Suspects
- poj 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- POJ-1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 - The Suspects
- POJ 1611 The Suspects
- Poj 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 the suspects
- POJ 1611 The Suspects
- Cisco Packet Tracer Student的路由器接口配置
- c,c++中const的用法
- 我的opengl实验备份代码
- Codeforces 584C Marina and Vasya
- 去掉xcode编译warning:ld: warning: directory not found for option '-L
- POJ 1611 The Suspects
- 《java入门第一季》之面向对象(成员方法)
- 颜色转变图片
- Linux设备模型(3)_Uevent
- Codeforces Round #349 (Div. 1) B. World Tour
- Kudu Consensus Design
- 无人机(总结的一个报告)
- Linux设备模型(4)_sysfs
- JAVA学习笔记-JAVA程序的基本结构