#include<iostream> using namespace std; #include<string.h> int dis[201][201], ans[201]; bool vis[201]; int i, j; void djstla(int begin, int end, int n) { memset(ans, 0x1f, sizeof(ans)); memset(vis, 0, sizeof(vis)); ans[begin] = 0; for (i = 1; i <= n; i++) { int min = 10000000, num = 300; for (j = 1; j <= n; j++) { if (!vis[j] && min > ans[j]) { min = ans[j]; num = j; } } /*if (num != 300) {*/ vis[num] = 1; for (j = 1; j <= n; j++) { if (!vis[j] && ans[j]>ans[num] + dis[num][j]) { ans[j] = ans[num] + dis[num][j]; } } /*} else { break; }*/ } /*if (ans[end] < 0x1f)*/ cout << ans[end] << endl; /*else cout << -1 << endl;*/ } int main() { int n, m; while
最短路(Djstla算法)
最新推荐文章于 2021-10-23 10:15:12 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)