感冒病毒 suspects 并查集
来源:互联网 发布:js调用json接口数据 编辑:程序博客网 时间:2024/05/03 12:27
题目大意:给定n个人,m个团,同一个团中只要有一个人感染病毒整个团就都感染病毒。现在0号感染了病毒,问总共有多少个人会感染病毒。
题目分析:简单的并查集。
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#include<cmath>#include<cctype>#include<cassert>#include<climits>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define ForD(i,n) for(int i=n;i;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define RepD(i,n) for(int i=n;i>=0;i--)#define MEM(a) memset(a,0,sizeof(a))#define MEMI(a) memset(a,127,sizeof(a))#define MEMi(a) memset(a,128,sizeof(a))#define INF (2139062143)#define phiF (1000000006)#define MAXN (1000000+10)typedef long long LL;int fa[30005],n,m,k,x,y,fx,fy;int get(int v){if (fa[v]!=v) fa[v]=get(fa[v]);return fa[v];}int main(){scanf("%d%d",&n,&m);Fork (i,0,n) fa[i]=i;For (i,m) {scanf("%d",&k);if (k){scanf("%d",&x);For (j,k-1){scanf("%d",&y);int fx,fy;fx=get(x);fy=get(y);if (fx!=fy) fa[fx]=fy;}}}fx=get(0);int ans=1;For (i,n) {fy=get(i);if (fx==fy) ans++;}printf("%d",ans);}
0 0
- 【并查集】感冒病毒 suspects
- 感冒病毒 suspects 并查集
- The Suspects 并查集
- POJ1611The Suspects并查集
- POJ_1611_The Suspects(并查集)
- 【并查集】ZOJ1789The Suspects
- The Suspects(并查集)
- 并查集 The Suspects
- The Suspects 并查集
- poj1611The Suspects(并查集)
- 并查集 - The Suspects
- The Suspects(并查集)
- 并查集----The Suspects
- The Suspects 并查集
- The Suspects -- 并查集
- 1611 The Suspects 并查集
- POJ 1611 The Suspects(并查集)
- POJ1611 The Suspects 并查集求解
- Yii中Flash数据的处理机制(源码分析)
- servlet过滤器、监听器、struts2拦截器的区别
- HDU 5735 Born Slippy(树形dp+可持久化)
- dts driver porting
- Redis介绍以及安装(Linux与windows)
- 感冒病毒 suspects 并查集
- 平移动画
- 谈谈Memcached与Redis
- MySQL关键字Distinct用法介绍
- tomcat启动,访问http://localhost:8080时报http status 404
- javascript学习笔记2
- Codeforces #364(Div.2)B.Cells Not Under Attack 【思维】
- Ehcache 整合Spring 使用页面、对象缓存
- 常用字符与ASCII代码对照表