Floyd
作者:
巷港
,
2022-03-05 16:05:04
,
所有人可见
,
阅读 129
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 210;
int d[N][N];
int n,m,k;
int main()
{
cin>>n>>m>>k;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
{
if (i==j) d[i][j]=0;
else d[i][j]=0x3f3f3f3f;
}
while (m--)
{
int a,b,c;
cin>>a>>b>>c;
d[a][b]=min(d[a][b],c);
}
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]);
while (k--)
{
int x,y;
cin>>x>>y;
if (d[x][y]>0x3f3f3f3f/2) puts("impossible");
else cout<<d[x][y]<<endl;
}
return 0;
}