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 (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7201 Accepted Submission(s):
2350
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.
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.
least time Kiki needs to spend ,if it’s impossible to find such a route ,just
output “-1”.
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
-1

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int node[],map[][],n,Min;
const int INF=; void dijkstra()
{
int vis[]= {};
int tm=,m;
node[tm]=;
vis[tm]=;
for(int i = ; i <= n; i++)
node[i] = INF;
for (int k=; k<=n; k++)
{
Min=INF;
for (int i=; i<=n; i++)
if (!vis[i])
{
if (node[i]>map[tm][i]+node[tm])
node[i]=map[tm][i]+node[tm];
if (Min>node[i])
{
Min=node[i];
m=i;
}
}
vis[m]=;
tm=m;
}
} int main ()
{
int m,s;
while (~scanf("%d%d%d",&n,&m,&s))
{
memset(map, INF, sizeof(map));
for (int i=; i<=m; i++)
{
int p,q,t;
cin>>p>>q>>t;
if (map[p][q]>t)
map[p][q]=t;
}
int w,cost;
cin>>w;
for (int i=; i<=w; i++)
{
scanf ("%d",&cost);
map[][cost]=;
}
dijkstra();
if(node[s] ==INF)
printf("-1\n");
else
printf("%d\n", node[s]);
}
return ;
}
hdu 2680 Choose the best route (dijkstra算法 最短路问题)的更多相关文章
- hdu 2680 Choose the best route
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki ...
- hdu 2680 Choose the best route (dijkstra算法)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2680 /************************************************* ...
- hdu 2680 Choose the best route 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目意思:实质就是给定一个多源点到单一终点的最短路. 卑鄙题---有向图.初始化map时 千万不 ...
- HDU 2680 Choose the best route(SPFA)
Problem DescriptionOne day , Kiki wants to visit one of her friends. As she is liable to carsickness ...
- HDU 2680 Choose the best route(多起点单终点最短路问题)题解
题意:小A要乘车到s车站,他有w个起始车站可选,问最短时间. 思路:用Floyd超时,Dijkstra遍历,但是也超时.仔细看看你会发现这道题目好像是多源点单终点问题,终点已经确定,那么我们可以直接转 ...
- HDU 2680 Choose the best route 最短路问题
题目描述:Kiki想去他的一个朋友家,他的朋友家包括所有的公交站点一共有n 个,一共有m条线路,线路都是单向的,然后Kiki可以在他附近的几个公交站乘车,求最短的路径长度是多少. 解题报告:这道题的特 ...
- HDU 2680 最短路 迪杰斯特拉算法 添加超级源点
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 【hdu 2544最短路】【Dijkstra算法模板题】
Dijkstra算法 分析 Dijkstra算法适用于边权为正的情况.它可用于计算正权图上的单源最短路( Single-Source Shortest Paths, SSSP) , 即从单个源点出发, ...
- HDU 2068 Choose the best route
http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one ...
随机推荐
- 【week6】psp
本周psp
- windows与linux下执行.class(包含main方法)
来源:http://blog.csdn.net/hanqunfeng/article/details/4327325 一般来说,执行一个java文件采用执行jar包的方式最为方便(java -jar ...
- [C/C++] C++抽象类
转自:http://www.cnblogs.com/dongsheng/p/3343939.html 一.纯虚函数定义 纯虚函数是在基类中声明的虚函数,它在基类中没有定义,但要求任何派生类都要定义自己 ...
- input 输入框不能点 readonly , disabled
只读 readonly="readonly" 不可用 disabled="disabled" 背景变 灰色
- 第20天:京东nav、footer部分制作
一.鼠标的4种状态 cursor:pointer; 鼠标变成小手cursor:default;小白cursor:move;移动cursor:text;文本输入 二.网页布局:1.input.butto ...
- 【bzoj1614】[Usaco2007 Jan]Telephone Lines架设电话线 二分+SPFA
题目描述 Farmer John打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司支付一定的费用. FJ的农场周围分布着N(1 <= N <= 1 ...
- HTML5语义元素总结
HTML5语义元素 语义=意义 语义元素=元素的意义 什么事语义元素? 一个语义元素能够清楚的描述其意义给浏览器和开发者. 无语义 元素实例:div.span.无需考虑内容. 语义 元素实例:fo ...
- P1297 [国家集训队]单选错位
题目背景 原 <网线切割>请前往P1577 题目描述 gx和lc去参加noip初赛,其中有一种题型叫单项选择题,顾名思义,只有一个选项是正确答案.试卷上共有n道单选题,第i道单选题有ai个 ...
- CentOS 文件隐藏属性
1.chattr用于配置文件的隐藏属性 语法: chattr [-RVf] [-+=aAcCdDeijsStTu] [-v version] files... 选项与参数: +:增加某个特殊参数,其他 ...
- [洛谷P4980]【模板】Polya定理
题目大意:给一个$n$个点的环染色,有$n$中颜色,问有多少种涂色方案是的旋转后本质不同 题解:$burnside$引理:$ans=\dfrac1{|G|}\sum\limits_{g\in G}A_ ...