Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用了63ms,希望能抛砖引玉

Posted by suikay at 2008-12-20 17:45:20 on Problem 2395 and last updated at 2008-12-20 17:45:50
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator