BZOJ 1975: [Sdoi2010]魔法猪学院

二次联通门 : BZOJ 1975: [Sdoi2010]魔法猪学院

 

 

 

 

/*
    BZOJ 1975: [Sdoi2010]魔法猪学院

    k短路
    统计一下在能量用完之前走了多少条到终点的路即可
*/
#include <cstdio>
#include <queue>
#include <iostream>
#include <cstring>
#define flo double 
#define rg register
#define Max 5010
#define INF 1e9
struct E { E *n; int v; flo d; } *Zlist[Max], *Flist[Max], poor[Max * 80], *Ta = poor;
int N, M; flo dis[Max], P; bool is[Max];
struct D 
{
    flo g; int id;
    bool operator < (const D &rhs) const 
    { return g + dis[id] > rhs.g + dis[rhs.id]; }
};
std :: queue <int> Q; std :: priority_queue <D> H;
inline void read (int &n)
{
    rg char c = getchar ();
    for (n = 0; !isdigit (c); c = getchar ());
    for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
}
int main (int argc, char *argv[])
{
    read (N), read (M); scanf ("%lf", &P); rg int i, j; int x, y; flo z;
    for (i = 1; i <= M; ++ i) 
    {
        read (x), read (y); scanf ("%lf", &z);
        ++ Ta, Ta->n = Zlist[x], Zlist[x] = Ta, Ta->v = y, Ta->d = z;
        ++ Ta, Ta->n = Flist[y], Flist[y] = Ta, Ta->v = x, Ta->d = z;
    }
    int n; E *e; int V;for (i = 1; i <= N; ++ i) dis[i] = INF;
    for (dis[N] = 0, is[N] = true, Q.push (N); !Q.empty (); Q.pop ())
        for (n = Q.front (), is[n] = false, e = Flist[n]; e; e = e->n)
            if (dis[(V = e->v)] > dis[n] + e->d)
            {
                dis[V] = dis[n] + e->d;
                if (!is[V]) is[V] = true, Q.push (V);
            }
    D r, _t; r.id = 1, r.g = 0; flo T = 0; int C = 0;
    for (H.push (r); !H.empty (); )
    {
        r = H.top (); H.pop ();
        if (r.id == N) { ++ C, T += r.g; if (T > P) break; };
        for (e = Zlist[r.id]; e; e = e->n)
            _t = r, _t.id = e->v, _t.g = r.g + e->d, H.push (_t);
    }
    printf ("%d", C - 1); return 0;
}

 

转载于:https://www.cnblogs.com/ZlycerQan/p/7581360.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值