题意:有编号为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 ?…
//#include<bits/stdc++.h> #include<iostream> #include<stdio.h> #define max1 50005 using namespace std; int pa[max1],vis[max1]; int find(int a) { while(a!=pa[a]) { pa[a]=pa[pa[a]]; a=pa[a]; } return a; } void build(int a,int b) { int fa=f…
#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; …
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…