poj2524 Ubiquitous Religions(并查集)】的更多相关文章

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…
题目链接. 分析: 给定 n 个点和 m 条无项边,求连通分量的数量.用并查集很简单. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <map> #include <queue> #include <cmath> using namespace s…
Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23093   Accepted: 11379 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 findi…
Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23090   Accepted: 11378 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 findi…
题目:http://poj.org/problem?id=2524 题意:问一个大学里学生的宗教,通过问一个学生可以知道另一个学生是不是跟他信仰同样的宗教.问学校里最多可能有多少个宗教. 也就是给定一个图的点数和相应的边,问有多少个连通分量. #include<stdio.h> #include<iostream> #include<string.h> using namespace std; ]; int find(int a) { if(bin[a]!=a) ret…
题目链接 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相连,所以自然想到用并查集. 初始时候 全部电…
Ubiquitous Religions 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…
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;int n,m;int bin[50001];int findx(int x){    int r=x;    while(r!=bin[r])        r=bin[r];    int j=x,k;    while(j!=r)    {        k=bin…
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基础并查集★1325&&poj1308 Is It A Tree? 基础并查集★1856 More is better 基础并查集★1102 Constructing Roads 基础最小生成树★1232 畅通工程 基础并查集★2120 Ice_cream's world I 基础并查集★212…