854. Floyd求最短路
#include<bits/stdc++.h>
using namespace std;
const int N = 210;
const int INF = 0x3f3f3f3f;
int n,m,k,d[N][N];
void floyd(){
for (int k = 1; k <= n; k ++ )
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= n; j ++ )
d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
}
int main()
{
cin >> n >> m >>k;
memset(d, INF, sizeof d);
for(int i = 1; i <= n; i++) d[i][i] = 0;
while(m--){
int x, y, z;
cin >> x >> y >> z;
d[x][y] = min(d[x][y],z);
}
floyd();
while(k--){
int x,y;
cin >> x >> y;
if(d[x][y] > INF/2) cout << "impossible"<<endl;
else cout << d[x][y]<<endl;
}
return 0;
}