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. chip based learning

    chip types Transistor mode of operation Digital chip: 0/1  -> digital clac Analog chip: sound / b ...

  2. mysql中的union操作(整理)

    mysql中的union操作(整理) 一.总结 一句话总结: union两侧的字段数和字段类型要是一样的 union可以接多个 orderby和排序可以在最后的union组合之后 1.union简单实 ...

  3. UML期末复习题

    看了网上的各种UML图的相关资料,找到的都是差不多一样的对图的基本介绍.之前复习的时候也想对不同UML图单独进行复习总结,后来发现这样复习好像没什么用,不能理解每个图之间的关系,所以就没有进一步总结. ...

  4. 用jeecg做个项目第三讲(自定义导入导出)

    1.导入 前端js和跳转页面 <t:dgToolBar title="导入单一模板" icon="icon-put" funname="Impo ...

  5. [Java复习] Spring IoC

    1. Spring bean的生命周期? 1. 对Bean进行实例化(相当于new) 对于BeanFactory 当客户向容器请求一个尚未初始化的bean(或初始化bean需要注入另外一个尚未初始化的 ...

  6. pymysql检查是否断开, 断开重连

    python mysql使用持久链接 python链接mysql中没有长链接的概念,但我们可以利用mysql的ping机制,来实现长链接功能~ 思路: 1 python mysql 的cping 函数 ...

  7. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_06-vuejs研究-vuejs基础-v-on指令

    3.v-on绑定一个按钮的单击事件 计算的按钮上加事件 点击计算的按钮,弹出的事件 定义一个Result的变量

  8. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_07-vuejs研究-vuejs基础-v-bind指令

    4.v-bind v-bind:无法双向绑定’ 1.作用: v‐bind可以将数据对象绑定在dom的任意属性中. v‐bind可以给dom对象绑定一个或多个特性,例如动态绑定style和class 2 ...

  9. 图解 HTTP 笔记(五)——Web 服务器

    该章的主要内容是讲解与 HTTP 协作的 Web 服务器 一.用单台虚拟主机实现多个域名 基于虚拟主机的功能,可以只使用一台物理机实现多个域名的网站部署. 在互联网上,域名通过 DNS 域名解析系统可 ...

  10. PHPCMS全局自定义函数 获取用户信息的办法

    在这个文件中增加即可\phpcms\libs\functions\global.func.php /** * 获取当前登陆者的信息 * @param $f 取什么字段F就传什么值 */ functio ...