poj 1611 the suspects
来源:互联网 发布:php 生成xml 编辑:程序博客网 时间:2024/06/08 00:52
这个题目就是说现在已经知道0号是非典型性肺炎的患者,现在给你一些人及关系网就是说这些人只要有一个人得病其余的人也全都得病,现在问一共有多少人得病。其实这个题目说简单很简单,其实你只要按照最普通的并查集做法,然后另加一个数组记录这个团体一共有多少人得病就好了。这个题目和hdu virtual friend这个题目是有很大的相似处的,简单模仿一下就都会写了。
#include<iostream>#include<stdio.h>using namespace std;int father[30000],count[30000];int find_ant(int x){if(x!=father[x])father[x]=find_ant(father[x]);return father[x];}void unin(int x,int y){int x_x,y_y;x_x=find_ant(x);y_y=find_ant(y);if(x_x!=y_y){father[y_y]=x_x;count[x_x]=count[y_y]+count[x_x];}}int main(){int n,m,i,k,j,flag,a,t;while(cin>>n>>m){if(n==0&&m==0)break;for(i=0;i<=n-1;i++){father[i]=i;count[i]=1;}for(i=1;i<=m;i++){scanf("%d",&k);if(k==0)continue;scanf("%d",&flag);for(j=2;j<=k;j++){scanf("%d",&a);unin(flag,a);}}t=find_ant(0);cout<<count[t]<<endl;}return 0;}
- POJ 1611 The Suspects
- poj 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- POJ-1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 - The Suspects
- POJ 1611 The Suspects
- Poj 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 the suspects
- POJ 1611 The Suspects
- 窗体背景的设置,设置颜色,和图片
- AndroidManifest.xml文件详解(receiver)
- 浅谈filter中的chain.doFilter(request, response)的作用
- 虚函数的实现机制
- 编辑利器 vim 培训笔记--入门好帮手
- poj 1611 the suspects
- Intellij IDEA使用入门
- 数据库锁、事务以及隔离级别的一点领悟
- How to test SOAP web service via SOAPUI
- HDU2005:第几天?
- linux下隐藏鼠标的方法
- JAVA画SVG图(Batik框架)GVTComponentDemo
- 第11周-项目1
- UBI文件系统简介