zoj 1789 The Suspects
来源:互联网 发布:怎么在淘宝店里卖二手 编辑:程序博客网 时间:2024/05/22 00:38
这道题是并查集的题,写过这道题之后,我明白了一点,就是从根上改变所属father域
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int p[30000+100];int a[30000+100];int find(int x){ if(p[x] == x) return x; p[x] = find(p[x]); return p[x];}int main(){ int n,m,k,i,count,temp; while(scanf("%d%d",&n,&m) == 2,n*n+m*m) { for(i=0;i<n;i++) p[i] = i; while(m--) { scanf("%d",&k); for(i=0;i<k;i++) scanf("%d",&a[i]); for(i=0;i<k-1;i++) if(find(p[a[i]]) != find(p[a[i+1]])) p[find(p[a[i+1]])] = find(p[a[0]]); } count = 0; for(i=0;i<n;i++) if(find(i) == find(0)) count++; printf("%d\n",count); } return 0;}
- ZOJ 1789 The Suspects
- zoj 1789 The Suspects
- zoj 1789 The Suspects
- zoj 1789 The Suspects
- zoj - 1789 - The Suspects
- zoj 1789 The Suspects
- zoj 1789The Suspects 并查集
- zoj 1789 || poj 1611 The Suspects(并查集)
- zoj 1789 The Suspects (并查集)
- zoj 1789||poj 1611 The Suspects(并查集,简单)
- POJ 1611 / ZOJ 1789: The Suspects - 并查集
- zoj The Suspects 并查集
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- 可执行文件的减肥
- POJ 1042 Gone Fishing
- java InputStream 相关类详细说明 2
- 解决vim和gedit显示中文乱码问题
- H2A系统若干问题的总结,整理
- zoj 1789 The Suspects
- vim高亮配置
- BugFree安装过程
- mysql中的索引
- WebService 最简单事例(入门级)
- java InputStream 相关类详细说明 1
- dojo3笔记
- 操作系统 任务管理 调度
- win7下不能替换系统文件的解决办法