const int N = 510;//节点个数 int n; int g[N][N];//图 int dist[N];//距离 bool st[N];//判断点是否访问过 int dijkstra(int s)//s表示起点,求s到任意点的最短距离 { memset(dist, 0x3f, sizeof dist); dist[s] = 0; for (int i = 0; i < n; i ++ ) { int t = -1; for (int j = 0; j < n; j ++ ) if (!st[j] && (t == -1 || dist[t] > dist[j])) t = j; for (int j = 0; j < n; j ++ ) dist[j] = min(dist[j], dist[t] + g[t][j]); st[t] = true; } if (dist[n] == 0x3f3f3f3f) return -1; return dist[n]; }
标签:dist,int,邻接矩阵,st,++,Dijkstra,return,板子 From: https://www.cnblogs.com/wockcow/p/18096734