一 、题目链接
单元最短路径
二、题目截图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/575bd24eba0b5b513136b262852b7077.png)
三、 代码答案:(c语言实现已AC)
#include <stdio.h>
#include <limits.h>
#define MAXN 2500
#define MAXM 6200
int n, m, s, t;
int dis[MAXN+1];
int vis[MAXN+1];
int head[MAXN+1];
typedef struct {
int v, w, next;
} Edge;
Edge edges[MAXM*2];
int edgeCnt = 0;
void addEdge(int u, int v, int w) {
edgeCnt++;
edges[edgeCnt].v = v;
edges[edgeCnt].w = w;
edges[edgeCnt].next = head[u];
head[u] = edgeCnt;
}
void dijkstra() {
for (int i = 1; i <= n; i++) {
dis[i] = INT_MAX;
}
dis[s] = 0;
for (int i = 1; i <= n; i++) {
int u = 0;
for (int j = 1; j <= n; j++) {
if (!vis[j] && (u == 0 || dis[j] < dis[u])) {
u = j;
}
}
vis[u] = 1;
for (int j = head[u]; j != 0; j = edges[j].next) {
int v = edges[j].v;
int w = edges[j].w;
if (dis[u] + w < dis[v]) {
dis[v] = dis[u] + w;
}
}
}
}
int main() {
scanf("%d%d%d%d", &n, &m, &s, &t);
for (int i = 1; i <= m; i++) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
addEdge(u, v, w);
addEdge(v, u, w);
}
dijkstra();
printf("%d\n", dis[t]);
return 0;
}