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 |
试探的点确实只能放在第一重循环!!!#include <stdio.h> #define INF 999999 #define M 100+10 #define min(a,b) a>b?b:a int map[M][M]; int n; void init() { int i,j; for(i=1;i<=n;i++) for(j=1;j<=n;j++) { map[i][j]=INF; map[i][i]=0; } } void Flody() { int i,j,k; for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) map[i][j]=min(map[i][j],map[i][k]+map[k][j]); } } } void slove() { int i,j,k; int ans=INF; int ansnum; int maxnum; Flody(); for(i=1;i<=n;i++) { maxnum=-1; for(j=1;j<=n;j++) { if(i!=j) { if(maxnum<map[i][j]) { maxnum=map[i][j]; } } } if(maxnum<ans) { ans=maxnum; ansnum=i; } } if(ans==INF) printf("disjoint\n"); else printf("%d %d\n",ansnum,ans); } int main() { int i,j,k,m; while(scanf("%d",&n)!=EOF&&n) { init(); for(k=1;k<=n;k++) { scanf("%d",&m); for(;m>=1;m--) { scanf("%d%d",&i,&j); map[k][i]=j; } } slove(); } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator