逃跑(escape)

时间限制: 3 Sec  内存限制: 128 MB

题目描述

输入

第一行是5个正整数,n,m,k,S,T,分别代表无向图点数,边数,蝙蝠的数量,二小姐所在起点的编号,目标点的编号。
第二行是k个正整数,分别代表大小姐每个蝙蝠所在的起点的编号。接下来有m行,每行有4个正整数,u,v,q,p,分别是该边的起点、终点,蝙蝠通过该
路花费的代价,二小姐通过该路花费的代价。

输出

一行,一个整数,所有人物达到终点所需要的代价的和的最小值。

样例输入

5 5 2 3 4
1 5
1 2 3 5
3 2 3 5
2 4 4 9
3 4 9 6
5 4 1 1

样例输出

13
题解:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#include<ctime>
#include<vector>
using namespace std;
int n,m,a,src,des;
struct node
{
int next,to;
long long dis,dis2;
}edge[];
int head[],size=;
int b[];//蝙蝠所在点
long long v1[];//各点到终点
long long v2[];//二小姐到各点
long long v3[];
void putin(int from,int to,long long dis,long long dis2)
{
size++;
edge[size].next=head[from];
edge[size].to=to;
edge[size].dis=dis;
edge[size].dis2=dis2;
head[from]=size;
}
void in(int from,int to,long long dis,long long dis2)
{
putin(from,to,dis,dis2);
putin(to,from,dis,dis2);
}
void bfs1()
{
memset(v1,/,sizeof(v1));
int front=,tail=,i,j;
int p[],vis[]={};
p[tail++]=des;
v1[des]=;
vis[des]=;
while(front!=tail)
{
int x=p[front++];
front%=;
vis[x]=;
for(i=head[x];i!=-;i=edge[i].next)
{
int y=edge[i].to;
if(v1[y]>v1[x]+edge[i].dis)
{
v1[y]=v1[x]+edge[i].dis;
if(!vis[y])
{
vis[y]=;
p[tail++]=y;
tail%=;
}
}
}
}
}
void bfs2()
{
memset(v2,/,sizeof(v2));
int front=,tail=,i,j;
int p[],vis[]={};
p[tail++]=src;
v2[src]=;
vis[src]=;
while(front!=tail)
{
int x=p[front++];
front%=;
vis[x]=;
for(i=head[x];i!=-;i=edge[i].next)
{
int y=edge[i].to;
if(v2[y]>v2[x]+edge[i].dis2)
{
v2[y]=v2[x]+edge[i].dis2;
if(!vis[y])
{
vis[y]=;
p[tail++]=y;
tail%=;
}
}
}
}
}
void bfs3()
{
memset(v3,,sizeof(v3));
int front=,tail=,i,j;
int p[],vis[]={};
for(i=;i<=a;i++)
{
p[tail++]=b[i];
v3[b[i]]=v1[b[i]];
vis[b[i]]=;
}
while(front!=tail)
{
int x=p[front++];
front%=;
vis[x]=;
for(i=head[x];i!=-;i=edge[i].next)
{
int y=edge[i].to;
if(v3[y]<v3[x]-edge[i].dis)
{
v3[y]=v3[x]-edge[i].dis;
if(!vis[y])
{
vis[y]=;
p[tail++]=y;
tail%=;
}
}
}
}
}
long long ans,ans1;
int main()
{
memset(head,-,sizeof(head));
int i,j;
scanf("%d%d%d%d%d",&n,&m,&a,&src,&des);
for(i=;i<=a;i++)
scanf("%d",&b[i]);
for(i=;i<=m;i++)
{
int from,to;long long dis,dis2;
scanf("%d%d%lld%lld",&from,&to,&dis,&dis2);
in(from,to,dis,dis2);
}
bfs1();bfs2();bfs3();
ans+=v2[des];
for(i=;i<=a;i++)
ans+=v1[b[i]];
ans1=ans;
for(i=;i<=n;i++)
{
ans1=min(ans1,ans-v2[des]+v2[i]+v1[i]-v3[i]);
}
cout<<ans1;
return ;
}

逃跑(escape)的更多相关文章

  1. 【BZOJ-1340】Escape逃跑问题 最小割

    1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 264  Solved: 121[Submit] ...

  2. BZOJ 1340: [Baltic2007]Escape逃跑问题

    1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 285  Solved: 133[Submit] ...

  3. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  4. 【HDU - 3533】Escape(bfs)

    Escape  Descriptions: 一个人从(0,0)跑到(n,m),只有k点能量,一秒消耗一点,在图中有k个炮塔,给出炮塔的射击方向c,射击间隔t,子弹速度v,坐标x,y问这个人能不能安全到 ...

  5. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. 简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  7. c#模拟js escape方法

    public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...

  8. LYDSY热身赛 escape

    Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ...

  9. javascript escape()函数和unescape()函数

    javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ...

随机推荐

  1. Ajax第一课

    <script language="javascript"></script> Javascript 函数创建     function 函数名(){    ...

  2. arcgis属性选取like用法

    查询对象为ArcInfo coverage,shapefile, INFO table,dBASE table,ArcSDE data,ArcIMS 要素类,或者 ArcIMS image servi ...

  3. oracle AWR性能监控报告生成方法

    目前相当一部分公司会用到oracle,在做性能测试的时候,对数据库的监控很重要,那么这里先介绍下如何生成oracle自带的awr监控报告,而具体报告的内容分析会放在后续的博客中 oracle性能分析入 ...

  4. LinkedHashMap:我还能实现LRU

    众所周知,LinkedHashMap继承自HashMap,在原先的HashMap的基础上,它增加了Entry的双向链接. 有意思的是基于这种实现特性,LinkedHashMap 在迭代遍历时,取得键值 ...

  5. Robot Framework+Oracle

    本篇记录Robot Framework连接oracle数据库的安装 1.基础环境首先,robotframework的基础环境+DatabaseLibrary环境要准备好,这两个环境的搭建在前面已经讲过 ...

  6. 基于Android的上课助手的概况及第一周冲刺详情

    基于Android平台的上课助手 一.       功能简介 课表查询 课程提醒 空闲教室的查询 二.       开发环境 Android 三.       开发成员 组长:李志岩 成员:王亚蕊.孙 ...

  7. Plotting trees from Random Forest models with ggraph

    Today, I want to show how I use Thomas Lin Pederson's awesome ggraph package to plot decision trees ...

  8. A function to help graphical model checks of lm and ANOVA(转)

    As always a more colourful version of this post is available on rpubs. Even if LM are very simple mo ...

  9. cookie创建,删除

    Cookie 历来指就着牛奶一起吃的点心.然而,在因特网内,“Cookie”这个字有了完全不同的意思.那么“Cookie”到底是什么呢?“Cookie”是小量信息,由网络服务器发送出来以存储在网络浏览 ...

  10. javascript基础-表单

    图解:   表单只需要知道常用的,其他的了解原理就行.在实际项目中,序列化一般用库(jquery)带的方法.富文本引用组件.