P8724 [蓝桥杯 2020 省 AB3] 限高杆

原题链接

题解

分层图,太奥妙了
每层图都是一样的 d=0 的边建的图, d=1 就像梯子,可以去上一层走,总共有三层

code

#include<bits/stdc++.h>
using namespace std;
#define ll long long

inline void read(ll &x) {
    x = 0;
    ll flag = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')flag = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        x = (x << 3) + (x << 1) + (c ^ 48);
        c = getchar();
    }
    x *= flag;
}

inline void write(ll x)
{
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

struct node
{
    ll to, len;
};
vector<node> G[30015];
struct unit
{
    ll x, y, w;
};
struct fresh
{
    ll pos, val;
    bool operator<(const fresh &b)const
    {
        return val > b.val;
    }
};

ll dis[30015];
int main()
{
    memset(dis, 0x3f, sizeof dis);
    ll n, m;
    read(n);
    read(m);

    for(ll i = 1; i <= m; i++)
    {
        ll x, y, w, c;
        read(x);
        read(y);
        read(w);
        read(c);
        if(c)
        {
            G[x].push_back({y+n, w});
            G[x+n].push_back({y+2*n, w});
            G[y].push_back({x+n, w});
            G[y+n].push_back({x+2*n, w});
            continue;
        }

        G[x].push_back({y, w});
        G[y].push_back({x, w});
        G[x+n].push_back({y+n, w});
        G[y+n].push_back({x+n, w});
        G[x+2*n].push_back({y+2*n, w});
        G[y+2*n].push_back({x+2*n, w});
    }

    priority_queue<fresh> q;
    q.push({1, 0});
    while(q.size())
    {
        ll now = q.top().pos, val = q.top().val;
        q.pop();
        if(dis[now] <= val) continue;
        dis[now] = val;
        for(auto next: G[now])
        {
            ll to = next.to, len = next.len;
            if(dis[to] > dis[now] + len)
            {
                q.push({to, dis[now] + len});
            }
        }
    }

    // for(ll i = 1; i <= 3 * n; i++) cout << dis[i] << " ";
    write(dis[n] - min(dis[2*n], dis[3*n]));

    return 0;
}

posted @   纯粹的  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示