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:这样可以了,只要把colorset[]换成你想要的 Posted by:sunmoonstar_love at 2005-07-28 22:20:29 > int GetRoot(int x){ > if(colorset[x] < 0) return x; > else return GetRoot(colorset[x]); > } > > void Union (int a, int b){ > int rootA = GetRoot(a); > int rootB = GetRoot(b); > > if(rootA == rootB) return; > > if(colorset[rootA] <= colorset[rootB]){ > > colorset[rootA] += colorset[rootB]; > colorset[rootB] = rootA; > } > } else { > > colorset[rootB] += colorset[rootA]; > colorset[rootA] = rootB; > } > } > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator