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

a

Posted by azma at 2009-04-27 14:33:12 on Problem 3615
#include <stdio.h>

int D [300][300];

int main () {
	int i,j,k,t,a,b,c,N,M,T;
	scanf("%d%d%d",&N,&M,&T);
	for(i = 0;i < N;i++)for(j = 0;j < N;j++)D[i][j] = 1000000000;
	for(i = 0;i < M;i++) {
		scanf("%d%d%d",&a,&b,&c);
		a--,b--;
		if(D[a][b]>c) D[a][b] = c;
	}
	for(k = 0;k < N;k++)
		for(i = 0;i < N;i++)
			for(j = 0;j < N;j++){
				if(D[i][k] > D[k][j]) t = D[i][k]; else t = D[k][j];
				if(D[i][j] > t) D[i][j] = t;
			}
	for(i = 0;i < T;i++) {
		scanf("%d%d",&a,&b);
		a--,b--;
		printf("%d\n",D[a][b] < 1000000000 ? D[a][b] : -1);
	}
	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