Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others.   In the Not-Spr…
( ̄▽ ̄)" #include<iostream> #include<cstdio> using namespace std; ]; void makeSet(int n) //初始化,n个元素,处于单独集合 { ;i<n;i++) fa[i]=i; } int findSet(int x) //找到该点的粑粑 { return fa[x]=fa[x]==x?x:findSet(fa[x]); } void unionSet(int x,int y) //粑粑相同的…
题意: 有N个学生,编号为0-n-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染, 并且这些人如果还参加了别的社团,他所在的社团照样全部感染,社团个数为m,求感染的人数. 输入: n代表人数,m代表社团数 社团的人数,第一个人编号,…… …… #include<stdio.h> ; int n,m,k; ]; ]; //total[GetParent(a)] 是a所在的group的人数 int GetParent(int a) {//获取a的根,并把a的父节点改为跟 if(pare…
并查集的模板题,为了避免麻烦,合并的时候根节点大的合并到小的结点. #include<cstdio> #include<algorithm> using namespace std; const int maxn = 33333; int fa[maxn]; int num[maxn]; int n,m,t; void init(){ for(int i = 0; i < n; i++) {fa[i] = i; num[i] = 1;} } int find_father(i…
http://210.34.193.66:8080/vj/Contest.jsp?cid=162#P7 思路:用并查集合并集合,最后遍历,找到集合的根的个数. 并查集是森林,森林中的每一颗树是一个集合.我们用一个数组,数组的下标是元素的值.数组存放着其父节点的位置.这样我们就能用数组画出多颗树. 也就是并查集. 初始化并查集,n含义如题. 在并查集中查找数值为x的根节点.根节点的父节点就是本身,当不是跟节点是,继续找. 并查集路径压缩(优化).在获得了跟节点后,把查找过程中遇到的节点比属于同一集…
The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁.为了减少传播给别人的机会, 最好的策略是隔离可能的患者. 在Not-Spreading-Your-Sickness大学( NSYSU), 有许多学生团体.同一组的学生经常彼此相通,一个学生可以同时加入几个小组.为了防止…
The Suspects   Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 20596   Accepted: 9998 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003.…
Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others. In t…
原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <stack> #include <queue> #include <cmath> #define ll l…
The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 35206   Accepted: 17097 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T…