#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <cstdlib> #include <cmath> #include <set> #include <map> #include <vector> #include <cstring> #define INF 100000000 using namespace std; int n,m,t; int ma[110][110]; int main(){ int q = 1; while(cin >>n >> m >> t,n||m||t){ for(int i = 0;i <= n;i++){ for(int j = 0;j <= n;j++){ ma[i][j] = INF; } } for(int i = 0;i < m;i++){ int x,y,w; cin >> x >> y >> w; ma[x][y] = w; ma[y][x] = w; } for(int k = 1;k <= n;k ++){ for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ ma[i][j] = min(ma[i][j],max(ma[i][k],ma[k][j]));//改变一下floyd的状态转移方程 } } } if(q!=1) cout << endl; printf("Case #%d\n",q++); for(int i = 0;i < t;i++){ int x,y; cin >> x >> y; if(ma[x][y] != INF) cout << ma[x][y] << endl; else cout << "no path" << endl; } } return 0; }
时间: 2024-10-06 00:38:44