#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pi pair<long long, long long>
int n, m, s, t;
//链式前向星存图
//存储边的结构体数组
struct node{
int to;
int nex;
ll w;
}edge[12405];
//以i号边为起点的边在edge数组中最后一次出现的位置, 初始化为-1
int head[2505];
ll arr[2505];
bool vis[2505];
int cnt = 0;
//堆优化
struct cmp{
bool operator()(pi a, pi b){
return a.first > b.first;
}
};
//链式前向星的构造函数
void add(int u, int v, int w){
edge[cnt].to = v;//该边的终点
edge[cnt].w = w;//该边的花费(权值)
edge[cnt].nex = head[u];//和该边起点想同的上一条边的位置
head[u] = cnt++;
}
void dij(int x){
priority_queue<pi, vector<pi>, cmp> q;
q.push({0, x});
arr[x] = 0;
while(!q.empty()){
int top = q.top().second;
q.pop();
if(vis[top]){
continue;
}
vis[top] = 1;
for(int i = head[top]; i != -1; i = edge[i].nex){
int v = edge[i].to;
if(vis[v] == 0 && a
最短路——迪杰斯特拉(Dijkstra)+ 堆优化 + 链式前向星 模板
于 2021-08-15 16:48:48 首次发布