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. C#程序调用CMD执行命令,将参数传递给cmd.exe

    proc.StartInfo.Arguments = "/c ping 10.2.2.125"; C#程序调用CMD执行命令 将参数传递给cmd.exe的(Passing an a ...

  2. Jquery.Data()和HTML标签的data-*属性

    Jquery.Data()和HTML标签的data-*属性 一.总结 一句话总结: 在页面中用到要用标签存数据还是用HTML标签的data-*属性,这样 不会破坏html本身的结构 1.使用HTML标 ...

  3. 性能分析 | Java进程CPU占用高导致的网页请求超时的故障排查

    一.发现问题的系统检查: 一个管理平台门户网页进统计页面提示请求超时,随进服务器操作系统检查load average超过4负载很大,PID为7163的进程占用到了800%多. 二.定位故障 根据这种故 ...

  4. [idea][转]理解 IntelliJ IDEA 的项目配置和Web部署

    1.项目配置的理解 IDEA 中最重要的各种设置项,就是这个 Project Structre 了,关乎你的项目运行,缺胳膊少腿都不行.最近公司正好也是用之前自己比较熟悉的IDEA而不是Eclipse ...

  5. Kinect关节数据

    3 -0.118269 0.655295 1.7431 930.03 139.5962 -0.124249 0.506111 1.79473 926.387 239.42820 -0.122777 0 ...

  6. 08ListView动态列表组件 以及循环动态数据

    效果: main.dart import 'package:flutter/material.dart'; import 'res/listData.dart'; /* ListView:参数 scr ...

  7. 修改Eclipse启动时的选择工作空间

    对于eclipse的默认的工作空间,如果不需要正常切换workspace的用户很方便,打开eclipse便自动进入默认的工作空间.而如果用户经常在多个workspace之间切换的话,启动eclipse ...

  8. opengl鼠标键盘控制相机漫游

    键盘wsad控制相机位移,鼠标左键按下控制相机旋转 效果如下 代码如下 #include <stdio.h> #include <string.h> #include < ...

  9. shell窗体实现代码雨(解闷用)

    命令过程 277 2019-11-07 17:14:39 wget https://sourceforge.net/projects/cmatrix/files/cmatrix/1.2a/cmatri ...

  10. sql server新旧数据库的表结构差异

    sql server编写通用脚本自动检查两个不同服务器的新旧数据库的表结构差异 问题:工作过程中,不管是什么项目,伴随着项目不断升级版本,对应的项目数据库业务版本也不断升级,数据库出现新增表.修改表. ...