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

第一次dijkstra成功

Posted by lingyibin at 2010-09-07 18:41:11 on Problem 1502
本来以为我的程序是错的,一直调试……调试……过了一个多钟头后,没耐心了。于是把它提交一下试试,居然AC了。呵呵……
给出我的关键代码:


int dijkstra()
{
	int i,j,m,d[MAX],x;
	CLR(visited);
	for(i = 1; i <= n; i ++) d[i]=(i==1?0:INT_MAX);
	for(i = 1; i <= n; i ++)
	{
		m = INT_MAX,x = 0;
		for(j = 1; j <= n; j ++)
			if(!visited[j] && m >= d[j]) 
				x = j, m = d[j];
		visited[x] = 1;
		for(j = 1; j <= n; j ++)
			if(mat[x][j] && d[j] > d[x]+mat[x][j])
				d[j] = d[x]+mat[x][j];
	}

	return m;
}

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