分层图(最短路 模版)

本文深入探讨了如何在分层图中寻找最短路径,详细介绍了相关算法模板,包括关键步骤和实现技巧,帮助读者理解并应用于实际问题解决。
摘要由CSDN通过智能技术生成
#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] = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值