POJ 1611 The Suspects(并查集)
来源:互联网 发布:惠威m3音箱评测数据 编辑:程序博客网 时间:2024/06/01 10:21
并查集
#include<bits/stdc++.h>using namespace std;int f[30020];int find(int x){ if(f[x]!=x) f[x]=find(f[x]); return f[x];}void make(int a,int b){ int f1=find(a); int f2=find(b); if(f1!=f2) f[f2]=f1;}int main(){ int n,m,a,b,k; int kase=1; while(scanf("%d%d",&n,&m)==2) { if(n==0&&m==0) break; for(int i=0;i<=n;i++) f[i]=i; for(int i=1;i<=m;i++) { scanf("%d%d",&k,&a); for(int i=1;i<=k-1;i++) { scanf("%d",&b); make(a,b); } } int ans=0; for(int i=0;i<=n;i++) { if(find(i)==find(0)) ans++; } printf("%d\n",ans); } return 0;}
1 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 1611The 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(并查集)
- PACS系统在医院里上线遇到的问题一览
- java自动装箱陷阱
- 芯片封装形式(网上到处找的)
- POJ 1088 滑雪 DP
- java中表达式的相关问题
- POJ 1611 The Suspects(并查集)
- mysql创建定时任务
- iOS的四种方法读取文件内容
- 数据分析站点导航
- enq: TT – contention等待事件
- Python数据分析环境搭建——linux篇
- poj 3261 后缀数组
- 读取简单的CSV文件
- 2014.7.24 - 多校2