枚举,最短路。

求出5个点出发的最短路,然后枚举一下这些点之间走的顺序。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int INF=0x7FFFFFFF;
const int maxn=;
int n,m,sz;
struct Edge {int u,v,w,nx; }e[];
int h[maxn];
int s,p1,q1,p2,q2;
int dis[maxn][maxn];
bool flag[maxn]; void add(int a,int b,int c)
{
e[sz].u=a;
e[sz].v=b;
e[sz].w=c;
e[sz].nx=h[a];
h[a]=sz++;
} void spfa(int st)
{
for(int i=;i<=n;i++) dis[st][i]=INF;
queue<int>Q; memset(flag,,sizeof flag);
flag[st]=; Q.push(st); dis[st][st]=; while(!Q.empty())
{
int f=Q.front(); Q.pop(); flag[f]=;
for(int i=h[f];i!=-;i=e[i].nx)
{
if(dis[st][f]+e[i].w<dis[st][e[i].v])
{
dis[st][e[i].v]=dis[st][f]+e[i].w;
if(flag[e[i].v]==)
{
flag[e[i].v]=;
Q.push(e[i].v);
}
}
}
}
} int main()
{
while(~scanf("%d%d",&n,&m))
{
scanf("%d%d%d%d%d",&s,&p1,&q1,&p2,&q2); memset(h,-,sizeof h); sz=; for(int i=;i<=m;i++)
{
int u,v,w; scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
} spfa(s); spfa(p1); spfa(p2); spfa(q1); spfa(q2); LL Ans[];
Ans[]=(LL)dis[s][p1]+(LL)dis[p1][q1]+(LL)dis[q1][p2]+(LL)dis[p2][q2];
Ans[]=(LL)dis[s][p1]+(LL)dis[p1][p2]+(LL)dis[p2][q1]+(LL)dis[q1][q2];
Ans[]=(LL)dis[s][p1]+(LL)dis[p1][p2]+(LL)dis[p2][q2]+(LL)dis[q2][q1];
Ans[]=(LL)dis[s][p2]+(LL)dis[p2][q2]+(LL)dis[q2][p1]+(LL)dis[p1][q1];
Ans[]=(LL)dis[s][p2]+(LL)dis[p2][p1]+(LL)dis[p1][q1]+(LL)dis[q1][q2];
Ans[]=(LL)dis[s][p2]+(LL)dis[p2][p1]+(LL)dis[p1][q2]+(LL)dis[q2][q1];
LL ans=Ans[];
for(int i=;i<;i++) ans=min(ans,Ans[i]); printf("%lld\n",ans);
}
return ;
}

FZU 2243 Daxia like uber的更多相关文章

  1. 【最短路】FOJ 2243 Daxia like uber

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2243 题目大意: 给一张N个点M条边的有向图,从s出发,把在x1的人送到y1,在x2的人送到y2用的最短距离 ...

  2. FZU 2240 Daxia & Suneast's problem

    博弈,$SG$函数,规律,线段树. 这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢.修改操作和区间查询的话可以用线段树维护一下区间异或和. 数据那么大 ...

  3. FZU 2238 Daxia & Wzc's problem

    公式. $a×C_{m + i - 1}^m + d×C_{m + i - 1}^{m + 1}$. 推导过程可以看http://blog.csdn.net/queuelovestack/articl ...

  4. FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)

    Problem A Daxia & Wzc's problem Accept: 42    Submit: 228Time Limit: 1000 mSec    Memory Limit : ...

  5. FZU Problem 2238 Daxia & Wzc's problem

    Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...

  6. FZU Problem 2244 Daxia want to buy house

    模拟题,注意: 1.那两个贷款都是向银行贷的,就是两个贷款的总额不能超过70%,就算公积金贷款能贷也不行,我开始的时候以为公积金贷款是向公司借的,,欺负我这些小白嘛.... 2.最坑的地方 *0.7是 ...

  7. 【模拟】FOJ 2244 Daxia want to buy house

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2244 题目大意: 每月还款额=贷款本金×[月利率×(1+月利率)^还款月数]÷[(1+月利率)^还款月数-1 ...

  8. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

  9. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

随机推荐

  1. jQuery中的DOM操作《思维导图》

    首先,是关于jQuery中的DOM操作的<思维导图>,请点击这里:jQuery中的DOM操作 列表框的左右选项移动 <html> <head> <title& ...

  2. 关于ADB server didn't ACK * failed to start daemon *的问题

    查看5037端口被谁占用了, 开始--运行--CMD 到命令提示符,输入 netstat -aon|findstr "5037" 输入 tasklist|findstr " ...

  3. iOS view和viewController的生命周期

    一.ViewController的职责 对内管理与之关联的View,对外跟其他ViewController通信和协调.对于与之关联的View,ViewController总是在需要的时候才加载视图,并 ...

  4. 关于ToolStrip设置Location无效的问题

    问题现象 当多个ToolStrip使用ToolStripContainer布局时,可以让用户自己拖动工具栏,所以在程序关闭时必须保存用户拖动工具栏的位置,但是在再次打开程序后,还原回来的工具栏位置会有 ...

  5. android 视图设置多个setTag数据

    1)在string.xml 文件中添加 <item tyoe="id" name = "tag_first" /> <item tyoe=&q ...

  6. U盘安装CentOS 6.4 + Windows 7双系统 (Windows 7下安装 CentOS 6.4)

    最近在看<鸟哥私房菜:基础学习篇>,觉得很不错,想要装个windows 7 和 CentOS 6.4 双系统,在网上找了很多教程,觉得乱七八糟的,弄得很复杂,而且很多都不是很完整,对于新手 ...

  7. Yellow

    Yellow这首歌让我知道了yellow这个单词出了黄色的意思外,还有胆怯的,懦弱的意思~~~ 它是Coldplay 的歌曲,歌词很简单,但是有着莫名的忧伤感,值得一提的是这首歌的MV,一个长镜头给出 ...

  8. Android零点一度的区别——Matrix

    2013-07-07 导语:Matrix是android中对图像绘制的处理(旋转.放缩.平移等等),貌似书本翻页就是用这种方式处理的 正文: 1.基于坐标(px,py)旋转degrees度, post ...

  9. 杭电OJ——1011 Starship Troopers(dfs + 树形dp)

    Starship Troopers Problem Description You, the leader of Starship Troopers, are sent to destroy a ba ...

  10. sqlplus中显示sql执行计划和统计信息

    31 ,32 , 33 ,34  keywords : oracle  storage  structure 最详细讲解: 1:doc 1   logical  storage structure 2 ...