题目链接 https://www.luogu.org/problem/show?pid=3110

题目描述

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.

Bessie 和 Elsie在不同的区域放牧,他们希望花费最小的能量返回谷仓。从一个区域走到一个相连区域,Bessie要花费B单位的能量,Elsie要花费E单位的能量。

如果某次他们两走到同一个区域,Bessie 可以背着 Elsie走路,花费P单位的能量走到另外一个相连的区域,满足P

#include<iostream>
#include<cstring>
#include<cstdio>
#include <queue>
#include <vector>
using namespace std;
int b,e,p,n,m;
const int N=200005;
int to[N*4],nex[N*4],head[N*4];
int tot;
int dis[N*4],vis[N*4];
inline void add(int x,int y){++tot;nex[tot]=head[x];to[tot]=y;head[x]=tot;
}
int aa[N];
int bb[N];
int cc[N];
inline void spfa(int s,int f[]){queue<int> q;q.push(s);memset(vis,0,sizeof(vis));for(int i=1;i<=n;++i) f[i]=2147483640;vis[s]=1;f[s]=0;while(!q.empty()){int dmf=q.front();q.pop();vis[dmf]=0;for(int i=head[dmf];i;i=nex[i]){int h=to[i];if(f[h]>f[dmf]+1){f[h]=f[dmf]+1;if(!vis[h]){vis[h]=true;q.push(h);}}}}
}
int main(){scanf("%d%d%d%d%d",&b,&e,&p,&n,&m);for(int i=1;i<=m;++i){int u,v;scanf("%d%d",&u,&v);add(u,v);add(v,u);}spfa(1,aa);spfa(2,bb);spfa(n,cc);int ans=2147483640;for(int i=1;i<=n;++i){ans=min(ans,b*aa[i]+e*bb[i]+p*cc[i]);}printf("%d\n",ans);return 0;
}

三遍spfa 然后枚举一下相遇地点即可~~~

洛谷 P3110 [USACO14DEC]驮运Piggy Back spfa相关推荐

  1. 【洛谷3110】【USACO14DEC】驮运Piggy Back

    题目描述 Bessie and her sister Elsie graze in different fields during the day, and in the evening they b ...

  2. 驮运Piggy Back

    题目描述 Bessie and her sister Elsie graze in different fields during the day, and in the evening they b ...

  3. 洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

    P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N ...

  4. 洛谷 P3112 [USACO14DEC]后卫马克Guard Mark

    题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...

  5. 【洛谷 P1772】 [ZJOI2006]物流运输(Spfa,dp)

    题目链接 \(g[i][j]\)表示不走在\(i\text{~}j\)时间段中会关闭的港口(哪怕只关\(1\)天)从\(1\)到\(m\)的最短路. \(f[i]\)表示前\(i\)天的最小花费.于是 ...

  6. [洛谷1462 ]通往奥格瑞玛的道路---二分答案+spfa

    题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...

  7. 教你如何更改在洛谷里的运势

    如何更改你在洛谷里的运势 你会不会经常满怀期待的打开洛谷 却发现今天的运势是凶 多么令人伤心啊qwq 但是,今天我来教你,如何让运势瞬间变成大吉. 第一步:打开洛谷 然后-没了 第二步:右击写着&qu ...

  8. 洛谷P2904 [USACO08MAR]跨河River Crossing 动态规划

    洛谷P2904 [USACO08MAR]跨河River Crossing 动态规划 区间DP f[ i ] 表示 将 i 头牛 运了过去,然后John 又返回所需要的最少时间 1 #include & ...

  9. 【杂题总汇】NOIP2013(洛谷P1967) 货车运输

    [洛谷P1967] 货车运输 重做NOIP提高组ing... +传送门-洛谷P1967+ ◇ 题目(copy from 洛谷) 题目描述 A国有n座城市,编号从1到n,城市之间有m条双向道路.每一条道 ...

  10. 洛谷OJ上的A+B花(zhuang)式(bi)解法

    转眼间快到了8月,一想自己都毕业好久了,很怀念曾经在各大OJ上刷题的时光,今天无意在一个算法群里看到最近有个叫洛谷的oj网站貌似蛮火的,于是注册了一个下进去看一看,顺手打开了A+B problem,然 ...

最新文章

  1. SqlHelper简单实现(通过Expression和反射)2.特性和实体设计
  2. 文献学习(part32)--Density Peak Clustering Based on Relative Density Optimization
  3. SpringBoot2.0 基础案例(03):配置系统全局异常映射处理
  4. VictoriaMetrics入门与实战
  5. 高通音频驱动调试(十七)
  6. 全志F1c100s主线linux入坑记录 (2)芯片超频
  7. VS2008安装部署应用程序安装包制作过程
  8. 超好用的数学教学软件:几何画板Sketchpad for Mac中文版
  9. DELL PERC-10和 PERC-9阵列卡支持的操作系统版本
  10. 进程同步问题(二)——信号量机制
  11. java 获取field类型_获取Java类中所有Field
  12. android锁屏自动杀死,android 锁屏的防进程被杀
  13. 深度理解感受野(一)什么是感受野?
  14. iOS学习笔记-018.舒尔特表游戏
  15. 【工业大数据】工业大数据应用场景分析;工业大数据,从何做起
  16. 拉普拉斯矩阵(Laplacian matrix)的求解
  17. 决战面试(二)智力题考察
  18. pssh, pscp的用法
  19. 解锁高性能计算与区块链应用,阿里云Kubernetes服务召唤神龙
  20. Python OpenCV学习笔记之:博立叶变换

热门文章

  1. PostgreSQL外键为空(null)
  2. Ubuntu设置dns
  3. JavaSE Map集合 HashMap和Hashtable的区别 Collections(集合工具类) 集合练习 模拟斗地主(洗牌,发牌,看牌)
  4. c# meiju(摘)
  5. 新闻资讯|iPad mini 概念想象重新设计,配备更大的8.4英寸Liquid Retina显示屏
  6. 弱水三千,只取一瓢饮 的意思
  7. 【无标题】输入圆锥体半径r以及高度h,并计算它的体积。
  8. 每天一篇自然语言处理论文:202004
  9. 《javascript设计模式与开发实践》——第一章(面向对象的javascript)学习记录
  10. android 跨应用服务,跨应用启动Service,出现空指针