赞
踩
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[3010][3010], d[3010]; bool v[3010]; int n, m; void dijkstra() { memset(d, 0x3f, sizeof(d)); // dist数组 memset(v, 0, sizeof(v)); // 节点标记 d[1] = 0; for (int i = 1; i < n; i++) { // 重复进行n-1次 int x = 0; // 找到未标记节点中dist最小的 for (int j = 1; j <= n; j++) if (!v[j] && (x == 0 || d[j] < d[x])) x = j; v[x] = 1; // 用全局最小值点x更新其它节点 for (int y = 1; y <= n; y++) d[y] = min(d[y], d[x] + a[x][y]); } } int main() { cin >> n >> m; // 构建邻接矩阵 memset(a, 0x3f, sizeof(a)); for (int i = 1; i <= n; i++) a[i][i] = 0; for (int i = 1; i <= m; i++) { int x, y, z; scanf("%d%d%d", &x, &y, &z); a[x][y] = min(a[x]<
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。