| ||||||||||
| 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:fluke at 2006-08-31 16:53:48 你这个并查集不是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