floyd算法
作者:
呆比小昱
,
2021-12-15 17:13:50
,
所有人可见
,
阅读 286
floyd算法
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 210, INF = 1e9;
int n, m, Q;
int 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()
{
scanf("%d%d%d", &n, &m, &Q);
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] = INF;
while (m -- )
{
int a, b, w;
cin >> a >> b >> w;
d[a][b] = min(d[a][b], w);
}
floyd();
while (Q -- )
{
int a, b;
cin >> a >> b;
int res = d[a][b];
if (res > INF / 2) puts("impossible");
else printf("%d\n", res);
}
return 0;
}
我1803年的,姐姐哪年的?
弟弟你一定参加了鸦片战争吧
姐姐还是这么棒~
对了,我是1903年的呢~
原古时期大怪兽, 哇呜~哇呜~~~QWQ
我03年的,姐姐哪年的?