Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
a#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator