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

Please take error

Posted by Unlog at 2005-08-12 17:01:26 on Problem 2387
#include <fstream.h>
int n,m,D[1003][1003],B[1003],v[1003];
void input()
{
	cin >> m >> n;
	int i,a,b,value;
	for(i=1;i<=m;i++){
		cin >> a >> b >> value;
		D[a][b]=value;
		D[b][a]=value;
	}
}
void Dy()
{
	int i,j,min,ch;
	for(i=1;i<=n;i++){
		if(D[n][i]!=0)
			B[i]=D[n][i];
	}
	v[n]=1;
	for(i=2;i<=n;i++){
		min=9999999;
		for(j=1;j<=n;j++){
			if(B[j]!=0 && min>B[j] && v[j]!=1){
				min=B[j];
				ch=j;
			}
		}
		v[ch]=1;
		for(j=1;j<=n;j++){
			if(D[ch][j]!=0 && (B[j]==0 || B[j]>min+D[ch][j])){
				B[j]=min+D[ch][j];
			}
		}
	}
}
void operation()
{
	input();
	Dy();
	cout << B[1] << "\n";
}
int main()
{
	operation();
	return 0;
}

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