HDU-2544-最短路(floyd)

板子题,实验一下floyd。

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
int map[105][105];
int n, m;

int main()
{
    while (scanf("%d%d",&n,&m)&&n+m) {
        memset(map, INF, sizeof(map));
        int s, e, c;
        for (int i = 1; i <= m;i++) {
            scanf("%d%d%d", &s, &e, &c);
            if (c<map[s][e])
                map[s][e] = map[e][s] = c;
        }
        for (int k = 1; k <= n;k++) {
            for (int i = 1; i <= n;i++) {
                for (int j = 1; j <= n;j++) {
                    map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
                }
            }
        }
        printf("%d
", map[1][n]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/xyqxyq/p/10366587.html