题意:理解了题解的意思:是求在多条从a到b的路径中,每条路径都要选出它的最大路段,最后在这些路段中选出最小的即可。稍微修改一下Floyd就可以了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 110;
const int INF = 0x3f3f3f3f;
int d[MAXN][MAXN],C,S,Q,cas,flag;
void init(){
memset(d,INF,sizeof(d));
for (int i = 1; i <= C; i++)
d[i][i] = 0;
}
void read(){
init();
int u,v,w;
for (int i = 0; i < S; i++){
scanf("%d%d%d",&u,&v,&w);
d[u][v] = d[v][u] = w;
}
}
void Floyd(){
for (int k = 1; k <= C; k++)
for (int i = 1; i <= C; i++)
for (int j = 1; j <= C; j++)
d[i][j] = min(d[i][j],max(d[i][k],d[k][j]));
}
void solve(){
if (flag)
flag = 0;
else printf("\n");
printf("Case #%d\n",cas++);
int u,v;
for (int i = 0; i < Q; i++){
scanf("%d%d",&u,&v);
if (d[u][v] == INF)
printf("no path\n");
else printf("%d\n",d[u][v]);
}
}
int main(){
cas = 1;
flag = 1;
while (scanf("%d%d%d",&C,&S,&Q) != EOF && C+S+Q){
read();
Floyd();
solve();
}
return 0;
}