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 |
数据太弱了吧。。不是说到100吗?结果开到8就AC了,呵呵。。。。。#include <stdio.h> const int MAXN=8;//试了好多次试出来的值 const int MAXINT=1000000000; int f[MAXN][MAXN],n; void floyed() { int i,j,k; for (k=1;k<=n;k++) for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (f[i][j]>f[i][k]+f[k][j]) f[i][j]=f[i][k]+f[k][j]; } void read() { int i,j,t,y,person,time,max,temp; while (1) { scanf("%d",&n); if (!n) return; if (n==1) {printf("1 0\n");continue;} for (i=0;i<MAXN;i++) for (j=0;j<MAXN;j++) f[i][j]=MAXINT; for (i=1;i<=n;i++) { scanf("%d",&t); for (j=1;j<=t;j++) { scanf("%d %d",&y,&temp); f[i][y]=temp; } } floyed(); time=MAXINT; for (i=1;i<=n;i++) { max=0; for (j=1;j<=n;j++) if (i!=j) max=max<f[i][j]?f[i][j]:max; if (time>max) { time=max; person=i; } } if (time!=MAXINT) printf("%d %d\n",person,time); else printf("disjoint\n"); } } int main() { read(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator