3891: [Usaco2014 Dec]Piggy Back

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 116  Solved: 92
[Submit][Status][Discuss]

Description

Bessie and her sister Elsie graze in different fields during the day, and in the evening they both want to walk back to the barn to rest. Being clever bovines, they come up with a plan to minimize the total amount of energy they both spend while walking. Bessie spends B units of energy when walking from a field to an adjacent field, and Elsie spends E units of energy when she walks to an adjacent field. However, if Bessie and Elsie are together in the same field, Bessie can carry Elsie on her shoulders and both can move to an adjacent field while spending only P units of energy (where P might be considerably less than B+E, the amount Bessie and Elsie would have spent individually walking to the adjacent field). If P is very small, the most energy-efficient solution may involve Bessie and Elsie traveling to a common meeting field, then traveling together piggyback for the rest of the journey to the barn. Of course, if P is large, it may still make the most sense for Bessie and Elsie to travel separately. On a side note, Bessie and Elsie are both unhappy with the term "piggyback", as they don't see why the pigs on the farm should deserve all the credit for this remarkable form of transportation. Given B, E, and P, as well as the layout of the farm, please compute the minimum amount of energy required for Bessie and Elsie to reach the barn.

给定一个N个点M条边的无向图,其中Bessie在1号点,Elsie在2号点,它们的目的地为N号点。Bessie每经过一条边需要消耗B点能量,Elsie每经过一条边需要消耗E点能量。当它们相遇时,它们可以一起行走,此时它们每经过一条边需要消耗P点能量。求它们两个到达N号点时最少消耗多少能量?

Input

The first line of input contains the positive integers B, E, P, N, and M. All of these are at most 40,000. B, E, and P are described above. N is the number of fields in the farm (numbered 1..N, where N >= 3), and M is the number of connections between fields. Bessie and Elsie start in fields 1 and 2, respectively. The barn resides in field N. The next M lines in the input each describe a connection between a pair of different fields, specified by the integer indices of the two fields. Connections are bi-directional. It is always possible to travel from field 1 to field N, and field 2 to field N, along a series of such connections.

Output

A single integer specifying the minimum amount of energy Bessie and
Elsie collectively need to spend to reach the barn.  In the example
shown here, Bessie travels from 1 to 4 and Elsie travels from 2 to 3
to 4.  Then, they travel together from 4 to 7 to 8.
 

Sample Input

4 4 5 8 8
1 4
2 3
3 4
4 7
2 5
5 6
6 8
7 8

Sample Output

22

HINT

 

Source

题解:直接求出1、2、n点到各点的距离(由于是无向图所以方向神马的直接无视之),然后枚举各个汇合点,然后计算各个点的代价,然后输出,然后AC
一开始在怀疑这样子是否一定可行,是否会存在两者会合后再次分开的可能,但实际上,如果两个人一起行动更合适的话,那么相遇就不需要再分离;如果两个人不适合一起行动的话,那么干脆就不需要相遇。所以不要相遇了再分离,综上。(HansBug:嗨。。这话写的。。。为啥感觉越读越戳泪点TT)
(PS:程序里面我很逗比的还弄了个b作为反向map,实际上完全不必,一开始我没发现这个是无向图,所以b用来存储反向图,后来才发现我想多了TT)
 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g,w:longint;
next:point;
end;
map=array[..] of point;
arr=array[..] of longint;
var
i,j,k,l,m,n,a1,a2,a3:longint;
a,b:map;
c,e,f,g:arr;
d:array[..] of longint;
function min(x,y:longint):longint;inline;
begin
if x<y then min:=x else min:=y;
end;
function max(x,y:longint):longint;inline;
begin
if x>y then max:=x else max:=y;
end;
procedure add(x,y,z:longint;var a:map);inline;
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;
p^.next:=a[x];a[x]:=p;
end;
procedure spfa(x:longint;a:map;var c:arr);inline;
var f,r:longint;p:point;
begin
fillchar(g,sizeof(g),);
fillchar(c,sizeof(c),);
f:=;r:=;d[]:=x;g[x]:=;c[x]:=;
while f<r do
begin
p:=a[d[f]];
while p<>nil do
begin
if (c[p^.g]=) or((c[p^.g]>) and (c[p^.g]>(c[d[f]]+p^.w))) then
begin
c[p^.g]:=c[d[f]]+p^.w;
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
g[d[f]]:=;
inc(f);
end;
for i:= to n do dec(c[i]);
end; begin
readln(a1,a2,a3,n,m);
for i:= to n do a[i]:=nil;
for i:= to n do b[i]:=nil;
for i:= to m do
begin
readln(j,k);
add(j,k,,a);
add(k,j,,a);
end;
spfa(,a,c);
spfa(,a,e);
spfa(n,a,f);
l:=maxlongint;
for i:= to n do
if (c[i]<>-) and (e[i]<>-) and (f[i]<>-) then
l:=min(l,a1*c[i]+a2*e[i]+a3*f[i]);
writeln(l);
end.

3891: [Usaco2014 Dec]Piggy Back的更多相关文章

  1. bzoj3891[Usaco2014 Dec]Piggy Back*

    bzoj3891[Usaco2014 Dec]Piggy Back 题意: 给定一个N个点M条边的无向图,其中Bessie在1号点,Elsie在2号点,它们的目的地为N号点.Bessie每经过一条边需 ...

  2. 3893: [Usaco2014 Dec]Cow Jog

    3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 174  Solved: 87[Submit] ...

  3. 3892: [Usaco2014 Dec]Marathon

    3892: [Usaco2014 Dec]Marathon Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 169  Solved: 100[Submi ...

  4. [bzoj3893][Usaco2014 Dec]Cow Jog_暴力

    Cow Jog bzoj-3893 Usaco-2014 Dec 题目大意:题目链接. 注释:略. 想法: 先按照坐标排序. 我们发现每个牛只会被后面的牛影响. 所以我们考虑逆向枚举. 记录一下i+1 ...

  5. bzoj3892[Usaco2014 Dec]Marathon*

    bzoj3892[Usaco2014 Dec]Marathon 题意: 在二维平面上有N个点,从(x1,y1)到(x2,y2)的代价为|x1-x2|+|y1-y2|.求从1号点出发,按从1到N的顺序依 ...

  6. Bzoj3893 [Usaco2014 Dec]Cow Jog

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 302  Solved: 157 Description The cows are out exerci ...

  7. bzoj 3824: [Usaco2014 Dec]Guard Mark【状压dp】

    设f[s]为已经从上到下叠了状态为s的牛的最大稳定度,转移的话枚举没有在集合里并且强壮度>=当前集合牛重量和的用min(f[s],当前放进去的牛还能承受多种)来更新,高度的话直接看是否有合法集合 ...

  8. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. Raphael的Braille例子

    Raphael的Braille例子: 注意里面的split(' ')方法,竟然会split出来空元素: <%@ page language="java" contentTyp ...

  2. Java: 分解List<HashMap<String, String>>

    分解List<HashMap<String, String>> 的方法: List<HashMap<String, String>> mapList; ...

  3. 支付宝ios支付请求Java服务端签名报的一个错(ALI40247) 原创

    今天做app的支付宝支付,遇到些问题,以前做支付宝支付签名都是直接在客户端App进行,今天下了最新版本ios的支付宝支付demo,运行demo时底部有红色的显眼字体,告知用户签名必须在服务端进行... ...

  4. [CSS3] 学习笔记-CSS动画特效

    在CSS3中,出现了很多出彩的效果,例如2D.3D以及过度.动画和多列等.这些效果为页面设计添加了很多的可选设计. 1.2D.3D转换 转换,是使元素改变尺寸.形状.位置的一种效果:通过CSS3转换, ...

  5. WinForm 文件操作

    文件及文件夹操作 C/S:WinForm可以操作客户端文件 Client ServerB/S:浏览器服务 Brower Server 命名空间:using system .IO; 1. File类:文 ...

  6. WPF DEV CellTemplateSelector(一个正确使用DevExpress CellTemplateSelector的Demo)

    说明 我在项目中根据需求需要用到WPF Dev CellTemplateSelector时,遇到不少坑.曾一度想要放弃使用模板转换器,但又心有不甘,终于在不断努力下,达到了需求的要求.所以写下来和大家 ...

  7. 11G内存设置一例

    11G的内存设置参数有memory_target.memory_max_target.sga_target.pga_aggregate_target等. 一个特别繁忙的数据库,前期内存设置较低,物理内 ...

  8. java多线程安全问题 静态函数的修饰

    /* 如果同步函数被静态修饰后,使用的锁是什么呢? 通过验证,发现不在是this.因为静态方法中也不可以定义this. 静态进内存是,内存中没有本类对象,但是一定有该类对应的字节码文件对象. 类名.c ...

  9. java udp 发送小数数字(较难)

    代码全部来自:http://825635381.iteye.com/blog/2046882,在这里非常感谢了,我运行测试了下,非常正确,谢谢啊 服务端程序: package udpServer; i ...

  10. enote笔记语言(3)(ver0.2)

    what&why(why not)&how&when&where&which:紫色,象征着神秘而又潜蕴着强大的力量,故取紫色. key&keyword: ...