#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stack>
#include <queue>
#define flush(arr,i) memset(arr,i,sizeof(arr))
#define INF 0xfffffff
using namespace std;
const int maxn=1010;
//到节点的距离和第i个节点的前一个节点
int dis[maxn], pre[maxn];
//边集
int cost[maxn][maxn];
//是否在集合之中
bool vis[maxn];
int n, m, s;
/*
测试数据
---------
8 14 6
6 5 1
6 4 3
6 7 6
5 3 3
5 4 1
7 4 1
7 2 4
4 2 9
3 4 1
3 1 4
1 2 1
7 8 14
2 8 2
3 2 2
--------
*/
//数据录入和初始化
void initMap()
{
//没有进入集合
flush(vis, 0);
scanf("%d%d%d", &n, &m, &s);
int from, to, len;
for(int i = 1; i <= n; i++)
{
dis[i] = INF;
pre[i] = 0;
for(int j = 1; j <= n; j++)
cost[i][j] = INF;
}
for(int i = 0; i < m; i++)
{
scanf("%d%d%d",&from, &to, &len);
pr
Node:最短路径算法之Dijkstra
最新推荐文章于 2023-04-28 18:07:29 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)