并查集应用

http://acm.hdu.edu.cn/showproblem.php?pid=6380

#include
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=200010;
int n,m,k;
int a[maxn],fa[maxn];
int c[maxn];
int ans,ct,cnt,tmp,flag;
char s[maxn];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void un(int x,int y)
{
    x=find(x);y=find(y);
    if(x!=y)fa[x]=y;
}
int main()
{
    int T,cas=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&k);
        ans=0;
        for(int i=0;i<=n;i++){fa[i]=i;c[i]=0;}
        for(int i=0;i

 

你可能感兴趣的:(数据结构,比赛)