枚举,最短路。

求出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. c# 服务程序重启自身

    由于工作有这样的需求,于是各种寻找,但是都不满意,偶然间想起一个方法 1.修改服务的Program.cs文件如下 static void Main(string[] args) { //LoadFil ...

  2. windows 常用操作

      资源管理器 资源管理器中进入上一级目录:Alt+向上箭头     常用命令行命令 打开windows服务:services.msc     以管理员身份运行程序 按下Win键,在打开的窗口中输入命 ...

  3. HttpActionDescriptor,ASP.NET Web API又一个重要的描述对象

    HttpActionDescriptor,ASP.NET Web API又一个重要的描述对象 通过前面对“HttpController的激活”的介绍我们已经知道了ASP.NET Web API通过Ht ...

  4. ajaxFileUpload+struts2实现多文件上传

    以前有介绍过ajaxFileUpload实现文件上传,但那是单文件的,这次介绍多文件上传. 单文件上传参考:http://blog.csdn.net/itmyhome1990/article/deta ...

  5. myeclipse 配置 resin-pro-4.0.34

    热部署: 在 resin.xml 文件下 增加 <host id="" root-directory="."> <!-- webapps ca ...

  6. VS中为类,函数代码自动添加版权注释信息

    以web项目为例: 一:给类加注释 1.在visual studio 的安装路径下        如:[盘符]:\Program files\Microsoft Visual Studio 8\Com ...

  7. Ubuntu下OpenVPN客户端配置教程

    一般来说,提供Web服务的Linux服务器是很少需要连接OpenVPN的,但是个人Linux计算机在很多时候就需要连接OpenVPN了.比如以Linux为开发环境,需要连接公司的OpenVPN等等. ...

  8. 服务器如何防ssh服务暴力破解??

     如图: 当我们遭到暴力破解ssh服务该怎么办 内行看门道 外行看热闹  下面教大家几招办法: 1 密码足够的复杂,密码的长度要大于8位最好大于20位.密码的复杂度是密码要尽可能有数字.大小写字母和特 ...

  9. 微信公众号开发之网页中及时获取当前用户Openid及注意事项

    目录 (一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 (四)微信公众号开发之网页授权获取用户基本信息 (五)微信公众号开发之网页中及 ...

  10. In-Memory:内存优化数据的持久化和还原

    数据持久化是还原的前提,没有数据的持久化,就无法还原内存优化表的数据,SQL Server In-Memory OLTP的内存数据能够持久化存储,这意味着内存数据能够在SQL Server实例重启之后 ...