#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
const ll INF = 1e17;
const int M = 2e5+10;
ll cnt, k, n, m, t, v, u, ww;
ll dist[N][30], w[M];
int fir[N], nex[M], to[M];
struct Nod{
ll x, k, d;
bool operator<(const Nod &a)const{
return d > a.d;
}
};
void add(ll u, ll v, ll ww) {
nex[++ cnt] = fir[u];
fir[u] = cnt;
to[cnt] = v;
w[cnt] = ww;
}
ll dijstra(int n) {
memset(dist,127,sizeof(dist));
priority_queue<Nod> que;
que.push((Nod){1,0,0});
dist[1][0] = 0;
while(que.size()) {
Nod e = que.top(); que.pop();
if(e.d != dist[e.x][e.k]) continue;
if(e.x == n) return e.d;
for(int i = fir[e.x]; i; i = nex[i]) {
if(dist[to[i]][e.k] > dist[e.x][e.k] + w[i]) {
dist[to[i]][e.k] =
分层图(最短路 模版)
最新推荐文章于 2022-07-24 12:33:18 发布
本文深入探讨了如何在分层图中寻找最短路径,详细介绍了相关算法模板,包括关键步骤和实现技巧,帮助读者理解并应用于实际问题解决。
摘要由CSDN通过智能技术生成