您的位置:首页 > 其它

ZOJ 1789 The Suspects

2011-08-10 09:44 417 查看
The Suspects

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。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  im c