随笔分类 -  并查集

摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1232基本和1856相同,就是最后需要判断一下。。。。。View Code int count=0;for(i=1;i<=n;i++) //其父结点为其本身即可{ if(FindFa(i)==i) count++;}cout<<count-1<<endl; 阅读全文
posted @ 2011-04-06 15:10 聊聊IT那些事 阅读(224) 评论(0) 推荐(0)
摘要:View Code #include<iostream>using namespace std;#define M 10000001int father[M];int _max;int sum[M];int FindFa( int a ){if( father[a] == a ){return a;}return father[a] = FindFa( father[a] ); }void UnionFa( int a , int b ) //将a,b合并{father[b] = a; //把a设为b的父结点sum[a] += sum[b]; //当有元素加入a中时,使其个数加su 阅读全文
posted @ 2011-04-06 15:07 聊聊IT那些事 阅读(220) 评论(0) 推荐(0)