| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
说错是 是没有压缩 不是没有合并In Reply To:本题不用并查集 直接用差分就可以了 另 Posted by:sasnzy at 2006-09-01 08:38:10 > 你这个并查集不是O(1)的算法 没有合并
> struct SET
> {
> int p[maxn];
> void init()
> {
> for (int i=0;i<maxn;i++)
> p[i]=i;
> }
> int find(int a)
> {
> if (a!=p[a]) p[a]=find(p[a]);
> return p[a];
> }
> void merge(int a,int b)
> {
> p[find(b)]=find(a);
> }
>
> };
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator