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

ac了 wa了两次 先是T N 看错了 而后又看成1--n 其实是n--1

Posted by shicahju at 2011-07-29 09:54:23
#include<stdio.h>
#include<string.h>
#define MAX 99999999
long v[1005][1005];
int mark[1005];
main()
{
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF){
		if(n==0&&m==0){
			break;
		}
		int i,j;
		int a,b,c;
		int min;
		int u;
		for(i=1;i<=m;i++){
			for(j=1;j<=m;j++){
				v[i][j]=MAX;
			}
		}
		for(i=1;i<=n;i++){
			scanf("%d %d %d",&a,&b,&c);
			if(v[a][b]>c){
				v[a][b]=v[b][a]=c;
			}
		}
		memset(mark,0,sizeof(mark));
		mark[m]=1;
		for(i=1;i<=m;i++){
			min=MAX;
			for(j=m-1;j>=1;j--){
				if(!mark[j]){
					if(v[j][m]<min){
						min=v[j][m];
						u=j;
					}
				}
			}
			mark[u]=1;
			for(j=m-1;j>=1;j--){
				if(!mark[j]){
					if(v[j][m]>v[j][u]+v[u][m]){
						v[j][m]=v[j][u]+v[u][m];
					}
				}
			}
		}
		printf("%d\n",v[1][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