hdoj2680 Choose the best route
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10761 Accepted Submission(s): 3484
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.
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
1 -1 该题用到了最短路径万能源点, #include<queue> #include<stdio.h> #include<string.h> #define INL 0x3f3f3f3f using namespace std; int vid[10000],x[1080][1080],vist[10000]; int N,M,D; void spfa() { for(int i=0;i<=N;i++) { vist[i]=INL;vid[i]=0; } queue<int> q; vid[0]=1; q.push(0); vist[0]=0; while(!q.empty()) { int u=q.front(); q.pop(); vid[u]=0; for(int i=0;i<=N;i++) { if(vist[i]>vist[u]+x[u][i]) { vist[i]=vist[u]+x[u][i]; if(!vid[i]) { q.push(i); vid[i]=1; } } } } } int main() { while(scanf("%d%d%d",&N,&M,&D)!=EOF) { memset(x,INL,sizeof(x)); int a,b,c; for(int i=0;i<M;i++) { scanf("%d%d%d",&a,&b,&c); if(x[a][b]>c) x[a][b]=c; } int n,g,min; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&g); x[0][g]=0;//万能源点知识 } spfa(); if(vist[D]==INL) printf("-1\n"); else printf("%d\n",vist[D]); } return 0; }
hdoj2680 Choose the best route的更多相关文章
- hdu 2680 Choose the best route
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki ...
- HDU2680 Choose the best route 最短路 分类: ACM 2015-03-18 23:30 37人阅读 评论(0) 收藏
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Choose the best route(最短路)dijk
http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Time Limit: 2000/1000 MS (Java/ ...
- HDU2680 Choose the best route 2017-04-12 18:47 28人阅读 评论(0) 收藏
Choose the best route Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- 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(最短路)
题目链接: Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 最短路问题-- Dijkstra Choose the best route
Choose the best route Problem Description One day , Kiki wants to visit one of her friends. As she i ...
- hdoj 2680 choose the best route
Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsicknes ...
- HDU 2680 Choose the best route(SPFA)
Problem DescriptionOne day , Kiki wants to visit one of her friends. As she is liable to carsickness ...
随机推荐
- 厚溥教育1718部数据库连接作业答案,分装一个操作数据库而无需写SQL语句的函数
<?php header("Content-type:text/html;charset=utf8"); //PHP操作数据库的函数 function phpsql($dbc ...
- python 容器 用户注册登录系统
1. 列表和普通变量有什么区别 列表是数据类型,普通变量是用来存储数据的 可以把列表赋值给普通变量 2.存在列表 a = [11, 22, 33], 如何向列表中添加(增)新元素 44 a.appen ...
- c++_凑算式(最新方法)
凑算式 B DEFA + --- + ------- = 10 C GHI (如果显示有问题,可以参见[图1.jpg]) 这个算式中A~I代表1~9的数字,不同的字母代表不同的数字. 比如:6+8/3 ...
- 一个关于vue+mysql+express的全栈项目(三)------ 登录注册功能的实现(已经密码安全的设计)
本系列文章,主要是一个前端的视角来实现一些后端的功能,所以不会讲太多的前端东西,主要是分享做这个项目学到的一些东西,,,,, 好了闲话不多说,我们开始搭建后端服务,这里我们采用node的express ...
- [SQL]数据库中对值为数字,存储格式为varchar类型的字段进行排序
如果要对数据库中某存储数字的列(存储类型不为int)进行排序,可以在order by 里对该列进行转换, 即如 order by cast(mycolumn as int) desc
- Java学习--异常处理及其应用类
异常是运行时在代码序列中引起的非正常状况,换句话说,异常是运行时错误.在不支持异常处理的计算机语言中,必须手动检查和处理错误----通常是通过使用错误代码,等等.这种方式既笨拙又麻烦.Java的异常处 ...
- angularjs自己总结
1.模块 自定的directive和controller需要在同一个model下,或者另外的model depModules他了. ng-app要等于model的名字,所有的directive要在下面 ...
- 使用PL/SQL将sql脚本数据导入数据库
一. PL/SQL登录到数据库,使用tools工具进行导入.使用plsql登录到需要导入数据的数据库.点击工具栏上[tools]--[Import tables] 二.commit;
- Hibernate分页查询报错
不知道什么原因,就是这里报错的
- jenkins 提示No emails were triggered
发送邮件 Jenkins->系统管理->系统设置,在“邮件通知”里设置smtp服务器地址,以及发送者邮箱地址,在具体的任务构建完成以后,可以设置发送邮件,在某一个任务的"Add ...