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

bellman-ford 800k 204ms

Posted by stupidjohn at 2010-07-21 21:29:17 on Problem 1797
#include<iostream>
using namespace std;
int cross[1000001][3];
int n,m;
int place[1001];
int main()
{
	int cnt,x,i,max,a,b;
	cin>>cnt;
	for(x=1;x<=cnt;x++)
	{
		printf("Scenario #%d:\n",x);
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++) scanf("%d%d%d",&cross[i][0],&cross[i][1],&cross[i][2]);
		memset(place,0,sizeof(place));
		place[1]=0xfffffff;
		bool flag=true;
		while(flag)
		{
			flag=false;
			for(i=0;i<m;i++)
			{
				a=cross[i][0];b=cross[i][1];
				max=place[a]<cross[i][2]?place[a]:cross[i][2];
				if(max>place[b]) {place[b]=max;flag=true;}
				max=place[b]<cross[i][2]?place[b]:cross[i][2];
				if(max>place[a]) {place[a]=max;flag=true;}
			}
		}
		printf("%d\n\n",place[n]);
	}
	return 1;
}

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