题意:有编号为1到n的学生,然后有m组调查,每组调查中有a和b,表示该两个学生有同样的宗教信仰,问最多有多少种不同的宗教信仰 简单并查集 //#define LOCAL #include <iostream> #include <cstdio> #include <cstring> using namespace std; + ; int parent[maxn], n, m; int GetParent(int x) { return parent[x] == x ?…
题目链接: http://poj.org/problem?id=2524 Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 39369 Accepted: 18782 Description There are so many different religions in the world today that it is difficult to keep track of…
并查集的模板题,为了避免麻烦,合并的时候根节点大的合并到小的结点. #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://poj.org/problem?id=2588 Snakes Time Limit: 1000MS Memory Limit: 65536K Description Buffalo Bill wishes to cross a 1000x1000 square field. A number of snakes are on the field at various positions, and each snake can strike a particular…