标签:
源代码:
#include<cstdio>
int n,i[1001][1001];
const int maxint=10000000;
int main()
{
scanf("%d",&n);
for (int a=1;a<=n;a++)
for (int b=1;b<=n;b++)
{
scanf("%d",&i[a][b]);
if (i[a][b]==-1)
i[a][b]=maxint;
}
for (int a=1;a<=n;a++) //循环选取中间节点以更新最短路径。
for (int b=1;b<=n;b++)
for (int c=1;c<=n;c++)
if (i[b][a]+i[a][c]<i[b][c])
i[b][c]=i[b][a]+i[a][c];
scanf("%d",&n);
for (int a=1;a<=n;a++)
{
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",i[x][y]);
} //读入起点与终点,输出其最短路径。
return 0;
}
标签:
原文地址:http://www.cnblogs.com/koruko/p/5115677.html