POJ2524+并查集】的更多相关文章

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 28293   Accepted: 13787 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T…
题目链接:http://poj.org/problem?id=2524 题目大意:学校共有n个同学,告诉你m对同学信仰同一宗教,问这个学校学生信仰宗教的数目最多为多少. 例: Sample Input 10 91 21 31 41 51 61 71 81 91 1010 42 34 54 85 80 0 Sample Output Case 1: 1Case 2: 7 解题思路:直接套并查集的板子就可以了,初始化n个集合默认他们都信任不一样的宗教,初始就用n个宗教,每次给你的两个同学那个号码将他…
题意简单. 询问n个人的宗教关系. #include<stdio.h> ; int fa[ maxn ]; int vis[ maxn ]; void init( int n ){ ;i<=n;i++ ) {fa[i] = i;vis[i] = ;} } int find( int x ){ if( x==fa[x] ) return x; return fa[x] = find( fa[x] ); } void union_ab( int a,int b ){ int fa_a = f…
Description There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university believe in. You know that there are n stud…
题目链接 http://poj.org/problem?id=2524 题意 有n个学生,编号1~n,每个学生最多有1个宗教信仰,输入m组数据,每组数据包含a.b,表示同学a和同学b有相同的信仰,求在n名学生中最多存在多少种不同的宗教信仰. 思路 使用并查集解决. 代码 #include <iostream> #include <cstring> #include <cstdio> using namespace std; + ; int p[N]; void make…
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由于硬件的限制,一台电脑和另一台电脑能够相连当他们之间的距离小于d,或者还有一台电脑当中介,分别与两台电脑相连. 在修复的过程中,工作者会有两种操作,修复电脑和询问电脑a和电脑b是否相连.当询问的时候输出答案. 因为输入数据很大,需要快速判断电脑a和电脑b相连,所以自然想到用并查集. 初始时候 全部电…
题目链接. 分析: 给定 n 个点和 m 条无项边,求连通分量的数量.用并查集很简单. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <map> #include <queue> #include <cmath> using namespace s…
传送门:Ubiquitous Religions 许多次WA,贴上错的代码随时警示 简单没多加修饰的并查集 [WA1] #include <iostream> #include <cstdio> #include <algorithm> using namespace std; ; int n,m; int a,b,ans; int pre[maxn]; void init() { ;i<=n;i++){ pre[i] = i; } } int findPre(i…
并查集. #include<cstdio> #include<cstring> using namespace std; const int maxn = 55555; int fa[maxn]; int vis[maxn]; int n,m,t; void init(){ for(int i = 0; i < n; i++) {fa[i] = i;} memset(vis,0,sizeof(vis)); } int find_father(int u){ return fa…
Time limit5000 ms Memory limit65536 kB There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university believe in. You…