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 ...
随机推荐
- Windows下MongoDB的安装过程及基本配置
首先当然是到官网下载 MongoDB 了,点击进入后会看到下载页面,如下图所示: 安装有2种方式: 一种是通过直接点击下载的安装文件进行安装: 另一种是通过命令提示符来安装,下面我将直接通过第一种方式 ...
- Sublime Text 全局搜索Ctrl+Shift+F快捷键不能用
Sublime Text 全局搜索Ctrl+Shift+F快捷键不能用 和微软输入法的简繁体切换冲突了,关闭输入法的简繁体切换快捷键就好了! 文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢 ...
- kotlin陪伴对象
在kotlin中并没有静态类成员的概念,但并不等于实现类似于静态类成员的功能,陪伴对象可以解决这个问题 fun main(arg: Array<String>) { val create ...
- Goland 激活码
实测有效,分享下 Goland
- [C++]单源最短路径:迪杰斯特拉(Dijkstra)算法(贪心算法)
1 Dijkstra算法 1.1 算法基本信息 解决问题/提出背景 单源最短路径(在带权有向图中,求从某顶点到其余各顶点的最短路径) 算法思想 贪心算法 按路径长度递增的次序,依次产生最短路径的算法 ...
- 关于比较js中两个对象相等 ==
“如果两个操作数都是对象,则比较他们是不是同一个对象(引用的对象在内存中的地址一样),如果两个操作数都指向同一个对象,则相等操作符返回true,否则,返回false”. 我做了一个例子 functio ...
- iOS-调用网页聊天、拨打电话
@property (nonatomic,strong) UIButton *but;@property (nonatomic,strong) UIButton *but1;@property (st ...
- WebsSocket
本篇阅读目录 一.Websocket原理(握手.解密.加密) 二.基于Python实现简单示例 回到顶部 一.Websocket原理(握手.解密.加密) WebSocket协议是基于TCP的一种新的协 ...
- 【POJ - 3046】Ant Counting(多重集组合数)
Ant Counting 直接翻译了 Descriptions 贝西有T种蚂蚁共A只,每种蚂蚁有Ni只,同种蚂蚁不能区分,不同种蚂蚁可以区分,记Sum_i为i只蚂蚁构成不同的集合的方案数,问Sum_k ...
- linux netstat 查看网络连接状况
netstat -lnpnetstat -an |grep 127.0.0.1 tcp 0.0.0.0:* LISTEN tcp 0.0.0.0:* LISTEN [root@wang /]# net ...