ZOJ 1789 The Suspects
2011-08-10 09:44
417 查看
The Suspects
刷进去了,哈哈,第二~~根据个人经验少写子函数可以减少Run Memory。。。。。
2621134 2011-08-10 09:41:21 Accepted 1789 C 0 160 ylwh! #include <stdio.h> #include <stdlib.h> #define N 30001 int main() { int n, m, k, i, j, cnt, pre ; int now, temp, flag, r, x; while(scanf("%d%d", &n, &m), n) { cnt = 1; for(i=0; i<n; i++) pre[i] = i; for(i=0; i<m; i++) { scanf("%d", &k); scanf("%d", &temp); x = temp; while(x != pre[x]) x = pre[x]; pre[temp] = flag = x; for(j=1; j<k; j++) { scanf("%d", &temp); x = temp; while(x != pre[x]) x = pre[x]; pre[temp] = r = x; if(r!= flag) pre[r] = flag; } } x = 0; while(x != pre[x]) x = pre[x]; flag = x; for(i=1; i<n; i++) { x = i; while(x != pre[x]) x = pre[x]; if(x == flag) cnt++; } printf("%d\n", cnt); } return 0; }
刷进去了,哈哈,第二~~根据个人经验少写子函数可以减少Run Memory。。。。。
相关文章推荐
- zoj 1789 The Suspects
- zoj 1789 The Suspects
- zoj - 1789 - The Suspects
- zoj - 1789 - The Suspects
- ZOJ1789(The Suspects)j简单并查集
- ZOJ 1789 The Suspects
- zoj1789-The Suspects
- POJ 1611 / ZOJ 1789: The Suspects - 并查集
- zoj The Suspects 并查集
- zoj1074 To the Max
- ZOJ 1610 Count the Colors
- ZOJ 3466 The Hive II(插头DP)
- HDU 1010 && ZOJ 2110 Tempter of the bone (DFS + 奇偶剪枝)
- ZOJ 1006 Do the Untwist
- zoj 3228 Searching the String(AC自动机)
- C - The Suspects
- zoj 3885 The Exchange of Items 最小费用最大流
- zoj 1610 Count the Colors(线段树 区间更新)
- POJ 1611 The Suspects
- ZOJ 3781 Paint the Grid Reloaded 缩点+bfs