luogu P3110 [USACO14DEC]驮运Piggy Back

Posted ZlycerQan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了luogu P3110 [USACO14DEC]驮运Piggy Back相关的知识,希望对你有一定的参考价值。

二次联通门 : luogu P3110 [USACO14DEC]驮运Piggy Back

 

 

 

 

/*
    luogu P3110 [USACO14DEC]驮运Piggy Back

    Spfa 水题
*/
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>

const int BUF = 12312332;
char Buf[BUF], *buf = Buf;
#define INF 1e17
inline void read (int &now)
{
    for (now = 0; !isdigit (*buf); ++ buf);
    for (; isdigit (*buf); now = now * 10 + *buf - 0, ++ buf);
}

#define Max 50004

struct E { E *n; int v; };
E poor[Max], *list[Max], *Ta = poor;

inline void In (int u, int v)
{
    ++ Ta, Ta->v = v, Ta->n = list[u], list[u] = Ta;
    ++ Ta, Ta->v = u, Ta->n = list[v], list[v] = Ta;
}

int d[Max][3];
inline long long min (long long a, int b) { return a < b ? a : b; }
void Spfa (int S, int t)
{
    std :: queue <int> Queue;
    Queue.push (S),  d[S][t] = 0;
    for (int now; !Queue.empty (); Queue.pop ())
    {
        now = Queue.front ();
        for (E *e = list[now]; e; e = e->n)
            if (d[e->v][t] == -1)
            {
                d[e->v][t] = d[now][t] + 1;
                Queue.push (e->v);
            }
    }
    return ;
}

int Main ()
{
    fread (buf, 1, BUF, stdin); long long Answer = INF;
    int A, B, C, N, M; read (A), read (B), read (C);
    read (N), read (M); register int i, j; int x, y;
    for (i = 1; i <= M; ++ i)
        read (x), read (y), In (x, y);
    memset (d, -1, sizeof d);
    Spfa (1, 0), Spfa (2, 1), Spfa (N, 2);
    for (i = 1; i <= N; ++ i)
        Answer = min (Answer, d[i][0] * A + d[i][1] * B + C * d[i][2]);
    printf ("%lld", Answer);
    return 0;
}

int ZlycerQan = Main ();
int main (int argc, char *argv[]) {;}

 

以上是关于luogu P3110 [USACO14DEC]驮运Piggy Back的主要内容,如果未能解决你的问题,请参考以下文章

P3110 [USACO14DEC]Piggy Back S 题解

[luogu P3065] [USACO12DEC]第一!First!

Luogu P4122 [USACO17DEC]Blocked Billboard

[Luogu 3128] USACO15DEC Max Flow

luogu P2871 [USACO07DEC]手链Charm Bracelet

Luogu P4878 [USACO05DEC]布局