题意:有编号为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 ?…
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 32781 Accepted: 15902 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T…
Farm Irrigation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 6 Accepted Submission(s) : 3 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Benny has a spacious fa…
“打老虎”的背后 Time Limit: 2000/1000ms (Java/Others) Problem Description: “习大大”自担任国家主席以来大力反腐倡廉,各地打击贪腐力度也逐步加强.中国的这种令外国人不解的“风情”到底是何缘由呢?其实中国人都知道,所有的腐败问题基本上都源自官场上的“潜规则”,那“潜规则”又是源自什么呢?在中国盛行一句古语,“无关系不成方圆”,说的是中国是一个人情社会,纽带关系很强.一个人跟另一个人可能存在沾亲带故的某种“关系”,而所有通过这种“关系”的传…
B - 叠叠乐 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:30000KB 64bit IO Format:%lld & %llu Submit Status Description Input Output Sample Input Sample Output Hint Description Farmer John and Betsy are playing…
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-Sprea…
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 22389 Accepted: 11031 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 fin…
Steal the Treasure Time Limit: 10000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 775 Accepted Submission(s): 213 Problem Description The alliance of thieves decides to steal the treasure from country A.…
对与知道并查集的人来说这题太水了,裸的并查集,如果你要给别人讲述并查集可以使用这个题当做例题,代码中我使用了路径压缩,还是有一定优化作用的. #include <stdio.h> #include <string.h> const int maxn = 500005; int n, m; int pa[maxn]; void init() { for (int i = 1; i <= n; i++) { pa[i] = i; } } int find(int x) { if…
题目大意:有一些简单的化合物,每个化合物由两种元素组成,把这些化合物按顺序装车,若k个化合物正好包含k种元素,那么就会爆炸.避免爆炸,有些化合物就不能装车.求有多少个不能装车. 题目分析:若k个化合物正好包含k种元素,那么就会爆炸.我们把每种元素看成一个顶点,每种化合物看成一条边,若有环存在的时候正好是爆炸的情况,所以避免成环记录不能放的数量就行了. #include<iostream> #include<cstdio> using namespace std; ; int f[m…
Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, and all the friends do not want to stay with strang…
#include<stdio.h> #define N 31000 int pre[N]; int find(int x) { if(x!=pre[x]) pre[x]=find(pre[x]); return pre[x]; } int main() { int n,m,i,k,s,t; while(scanf("%d%d",&n,&m),n||m){ for(i=0;i<=n;i++) pre[i]=i; …