Choose the best route

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13229    Accepted Submission(s): 4280

Problem Description
One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city’s traffic route, and the stations which are near Kiki’s home so that she can take. You may suppose Kiki can change the bus at any station. Please find out the least time Kiki needs to spend. To make it easy, if the city have n bus stations ,the stations will been expressed as an integer 1,2,3…n.
 
Input
There are several test cases.
Each case begins with three integers n, m and s,(n<1000,m<20000,1=<s<=n) n stands for the number of bus stations in this city and m stands for the number of directed ways between bus stations .(Maybe there are several ways between two bus stations .) s stands for the bus station that near Kiki’s friend’s home.
Then follow m lines ,each line contains three integers p , q , t (0<t<=1000). means from station p to station q there is a way and it will costs t minutes .
Then a line with an integer w(0<w<n), means the number of stations Kiki can take at the beginning. Then follows w integers stands for these stations.
 
Output
The output contains one line for each data set : the least time Kiki needs to spend ,if it’s impossible to find such a route ,just output “-1”.
 
Sample Input
5 8 5
1 2 2
1 5 3
1 3 4
2 4 7
2 5 6
2 3 5
3 5 1
4 5 1
2
2 3
4 3 4
1 2 3
1 3 4
2 3 2
1
1
 
Sample Output
1
-1
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAX 0x3f3f3f3f
using namespace std;
int
map[][],d[],n,m,s,t;
void
dijkstra(int x)
{

int
i,j,min,mark,used[];
for
(i=;i<=n;i++)
{

used[i]=;
d[i]=map[x][i];
}

d[x]=;
used[x]=;
for
(i=;i<=n;i++)
{

min=MAX;
mark=-;
for
(j=;j<=n;j++)
{

if
(!used[j]&&d[j]<min)
{

min=d[j];
mark=j;
}
}

if
(mark==-)
break
;
used[mark]=;
for
(j=;j<=n;j++)
{

if
(!used[j]&&d[j]>d[mark]+map[mark][j])
d[j]=d[mark]+map[mark][j];
}
} }

int
main()
{

int
a,b,c,i,j;
while
(scanf("%d%d%d",&n,&m,&s)!=EOF)
{

memset(map,MAX,sizeof(map));
for
(i=;i<m;i++)
{

scanf("%d%d%d",&a,&b,&c);
if
(map[b][a]>c)
map[b][a]=c;
}

dijkstra(s);
int
start;
int
mi=MAX;
scanf("%d",&t);
for
(i=;i<t;i++)
{

scanf("%d",&start);
mi=mi<d[start]?mi:d[start];
}

if
(mi==MAX)
printf("-1\n");
else

printf("%d\n",mi);
}

return
;
}

hdu 2680 Dijstra的更多相关文章

  1. HDU - 2680 最短路 spfa 模板

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目大意,就是一个人可以从多个起点开始出发,看到终点的最短路是多少..只有可以运用和hdu2066 ...

  2. hdu 2680 Choose the best route

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki ...

  3. hdu 2680 Choose the best route (dijkstra算法)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2680 /************************************************* ...

  4. HDU 2680(最短路)(多个起始点)

    这道题也是死命TLE.. http://acm.hdu.edu.cn/showproblem.php?pid=2680 /* 使用pair代替结构 */ #include <iostream&g ...

  5. hdu 2680 Choose the best route (dijkstra算法 最短路问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Time Limit: 2000/1000 MS ( ...

  6. hdu 2680 Choose the best route 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目意思:实质就是给定一个多源点到单一终点的最短路. 卑鄙题---有向图.初始化map时 千万不 ...

  7. UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)

    UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...

  8. HDU 2680 最短路 迪杰斯特拉算法 添加超级源点

    Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. hdu 2680 最短路径(dijkstra算法+多源最短路径单源化求最小值)这题有点意思

    Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. 20175313 张黎仙《Java程序设计》第十周学习总结

    目录 一.教材学习内容总结 二.教材学习中的问题和解决过程 三.代码调试中的问题和解决过程 四.代码托管 五.心得体会 六.学习进度条 七.参考资料 一.教材学习内容总结 第十二章内容 主要内容 杂项 ...

  2. ArcGIS超级工具SPTOOLS-数据处理篇

    1. 数据处理 1.1  两个图层按重叠度赋属性 两个面层按重合度赋属性,下图把依据赋数据属性图层,按重合度,赋值给目标.,重合度设置为负值,取面积最大的. 1.2  分区域消除 按区域字段值相同的, ...

  3. 如何配置WAMP环境(主要是Apache与PHP)

    1.配置Apache 1.编辑Apache配置文件---http.conf(位于安装目录下的conf子目录内): 2.修改Document Root 和 Directory选项,这是修改Apache的 ...

  4. 属性 每秒10万吞吐 并发 架构 设计 58最核心的帖子中心服务IMC 类目服务 入口层是Java研发的,聚合层与检索层都是C语言研发的 电商系统里的SKU扩展服务

    小结: 1. 海量异构数据的存储问题 如何将不同品类,异构的数据统一存储起来呢? (1)全品类通用属性统一存储: (2)单品类特有属性,品类类型与通用属性json来进行存储: 2. 入口层是Java研 ...

  5. 生命周期和Zend引擎

    一切的开始:SAPI接口 SAPI(Server Application Programming Interface)指的是具体应用的编程接口.PHP脚本要执行有很多种方式,通过web服务器,或者直接 ...

  6. windows下redis配置密码

    redis安装后目录如下: 最简单的启动方式是直接双击redis-server.exe 如果要设置密码,首先打开配置文件,要注意的是这两个都是配置文件,记住你改的是哪一个,不放心的可以两个都改. 然后 ...

  7. 什么是UEFI

    UEFI是什么?也许我们大多数用户对这个概念很模糊.uefi可以做什么,有什么具体的应用?虽然不知道具体是做什么的,但是我们经常会在BIOS设置中发现UEFI的踪迹.因为现在越来越多的电脑已经使用了U ...

  8. 【计算机】DMA原理2

    DMA (直接存储器访问) DMA(Direct Memory Access,直接内存存取) 是所有现代电脑的重要特色,它允许不同速度的硬件装置来沟通,而不需要依赖于 CPU 的大量中断负载.否则,C ...

  9. 最新 东软java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.东软等10家互联网公司的校招Offer,因为某些自身原因最终选择了东软.6.7月主要是做系统复习.项目复盘.LeetCode ...

  10. JS节流和防抖的区分和实现详解

    参考链接:http://caibaojian.com/throttle-debounce.html