POJ 2607
一次FLOYD,再枚举。
注意题目要求的输出是什么哦。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 const int inf=9999999; 8 const int MAXN=505; 9 int maze[MAXN][MAXN]; 10 bool house[MAXN]; 11 int dis[MAXN],fire,n; 12 13 int main(){ 14 int u,v,w; 15 while(scanf("%d%d",&fire,&n)!=EOF){ 16 memset(house,false,sizeof(house)); 17 for(int i=1;i<MAXN;i++){ 18 maze[i][i]=0; dis[i]=inf; 19 for(int j=i+1;j<MAXN;j++) 20 maze[i][j]=maze[j][i]=inf; 21 } 22 int station; 23 for(int i=0;i<fire;i++){ 24 scanf("%d",&station); 25 house[station]=true; 26 dis[station]=0; 27 } 28 while(~scanf("%d%d%d",&u,&v,&w)){ 29 maze[u][v]=maze[v][u]=min(w,maze[u][v]); 30 } 31 for(int k=1;k<=n;k++){ 32 for(int i=1;i<=n;i++){ 33 for(int j=1;j<=n;j++){ 34 if(maze[i][k]+maze[k][j]<maze[i][j]){ 35 maze[i][j]=maze[i][k]+maze[k][j]; 36 } 37 } 38 } 39 } 40 for(int i=1;i<=n;i++){ 41 for(int j=1;j<=n;j++){ 42 if(house[j]) 43 dis[i]=min(dis[i],maze[i][j]); 44 } 45 } 46 // for(int i=1;i<=n;i++) 47 // cout<<dis[i]<<endl; 48 int tmp,ans,s=inf; 49 for(int i=1;i<=n;i++){ 50 tmp=0; 51 for(int j=1;j<=n;j++){ 52 tmp=max(min(dis[j],maze[i][j]),tmp); 53 } 54 if(tmp<s){ 55 s=tmp; ans=i; 56 } 57 } 58 printf("%d\n",ans); 59 } 60 return 0; 61 }