hdu 2680 Dijstra
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
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.
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<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的更多相关文章
- HDU - 2680 最短路 spfa 模板
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目大意,就是一个人可以从多个起点开始出发,看到终点的最短路是多少..只有可以运用和hdu2066 ...
- 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(最短路)(多个起始点)
这道题也是死命TLE.. http://acm.hdu.edu.cn/showproblem.php?pid=2680 /* 使用pair代替结构 */ #include <iostream&g ...
- 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 ( ...
- hdu 2680 Choose the best route 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目意思:实质就是给定一个多源点到单一终点的最短路. 卑鄙题---有向图.初始化map时 千万不 ...
- UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)
UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...
- HDU 2680 最短路 迪杰斯特拉算法 添加超级源点
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 2680 最短路径(dijkstra算法+多源最短路径单源化求最小值)这题有点意思
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- CTF辅助脚本
首先推荐这篇文章,网上有多次转载,这是我见过日期比较早的 CTF中那些脑洞大开的编码和加密 凯撒密码 flag='flag{abcdef}' c='' n=20 for i in flag: if ' ...
- Flutter中用ListView嵌套GridView报错异常
flutter中的ListView组件和GridView组件都是常用的布局组件,有时候ListView中需要嵌套GridView来使用,例如下图: 这种情况就需要在ListView里面再嵌套一个Gri ...
- DBeaver 客户端中时间显示问题解决
最近工作使用了一段时间的macOS,换了新的数据库客户端 DBeaver,无意中发现客户端显示时间不正确.时间保存之后显示比实际时间多13个小时整.可以判断是时区没有配置正确.无意中发现是DBeave ...
- vmware安装Linux
- CentOS7下安装php-soap扩展
一.首先更新yum yum update 二.查看php-soap相关的安装包,查看php版本,安装对应php版本的php-soap版本 php -v yum search php | grep -i ...
- [转][echarts]地图轮播
代码片断: 来自:https://blog.csdn.net/qq_36947128/article/details/90899564 function Play(){ chart.dispatchA ...
- Android:JACK编译错误汇总及解决
jack server交互命令: jack-admin start-server jack-admin kill-server jack-admin list-server jack-admin un ...
- 常用CSS媒体查询
@media screen and (orientation: portrait) { /*竖屏 css*/} @media screen and (orientation: landscape) { ...
- 免Root停用“Android键盘(AOSP)”
一.效果:隐藏手机状态栏输入法选择图标: 二.手段:使用ADB免root 停用系统默认Android键盘(AOSP),这里参考了大神的方法,在此表示感谢: 三.实现过程: 上图 下面就是按照大神的方法 ...
- markdown居中对齐,左对齐,右对齐
Markdown语法本身没有居中,但Markdown中支持基本的HTMl语法,可以使用HTML语法. 居中: <center>居中</center> 左对齐: <p al ...