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 |
用了63ms,希望能抛砖引玉In Reply To:谁有很牛的算法啊 教教偶们 鄙视自己6xxms的Kruskal.... Posted by:ccnuzhang at 2008-05-27 16:51:41 我是这样压缩路径的但还是用了63ms,希望那些大牛不吝指教撒~ int FindParent(int x) { if(parent[x] > 0) { parent[x] = FindParent(parent[x]); return parent[x]; } else return x; } //把层次小的 void Union(int x,int y) { x = FindParent(x); y = FindParent(y); if( x == y) return ; if(parent[x] < parent[y]) parent[y] = x; else if(parent[x] > parent[y]) parent[x] = y; else { parent[x]--; parent[y] = x; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator