并查集问题。
题意是说: 编号0 可能感染SARS。
然后有M个 团队,团队的人可能互相感染。
找出所有可能感染的SARS人。
把某个团队的并起来就好了。最后扫描一遍。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51#include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<queue> #include<map> #include<stack> #include<iostream> #include<list> #include<set> #include<cmath> #define INF 0x7fffffff #define eps 1e-6 using namespace std; int n,m; int fa[30001]; int father(int x) { if(x!=fa[x]) return fa[x]=father(fa[x]); } int main() { while(scanf("%d%d",&n,&m),n||m) { for(int i=0;i<=n;i++) fa[i]=i; while(m--) { int t,u,v; scanf("%d",&t); if(!t)continue; scanf("%d",&u); u=father(u); while(--t) { scanf("%d",&v); v=father(v); if(u==v)continue; fa[v]=u; } } int ans=0; int s=father(0); for(int i=0;i<=n;i++) if(father(i)==s)ans++; printf("%dn",ans); } }
最后
以上就是简单铃铛最近收集整理的关于POJ 1611 The Suspects的全部内容,更多相关POJ内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复