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 |
完全没有考虑不连通的情况,也可以过。。。。。还0MS,太水了#include<stdio.h> #include<string.h> #include<algorithm> #define inf 199999999 using namespace std; int map[105][105]; int link[105]; void init() { int i,j; for(i=0;i<105;i++) for(j=0;j<105;j++) map[i][j]=inf; for(i=0;i<105;i++) { map[i][0]=0; map[0][i]=0; } memset(link,0,sizeof(link)); } int main() { int i,j,k,t,n,w,l,min,num; while(scanf("%d",&t)!=EOF) { if(t==0) break; init(); min=inf; for(k=1;k<=t;k++) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d%d",&l,&w); map[k][l]=w; } } for(k=1;k<=t;k++) for(i=1;i<=t;i++) for(j=1;j<=t;j++) { if(map[i][k]!=inf&&map[k][j]!=inf) if(map[i][j]==inf||map[i][j]>map[i][k]+map[k][j]) { map[i][j]=map[i][k]+map[k][j]; } } for(i=1;i<=t;i++) map[i][i]=0; for(i=1;i<=t;i++) { for(j=1;j<=t;j++) { if(i!=j) link[i]=link[i]+map[i][j]; } if(link[i]<min) { min=link[i]; num=i; } } sort(map[num],map[num]+t+1); printf("%d %d\n",num,map[num][t]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator