博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Choose the best route
阅读量:2038 次
发布时间:2019-04-28

本文共 1900 字,大约阅读时间需要 6 分钟。

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 51 2 21 5 31 3 42 4 72 5 62 3 53 5 14 5 122 34 3 41 2 31 3 42 3 211

Sample Output

1-1
#include 
#include
#include
#include
#include
#include
using namespace std;#define MAXV 1010#define INF 0x3f3f3f3fint map[MAXV][MAXV],n,m,s,W;int vis[MAXV],cast[MAXV];void Dijkstra(){ int minn,pos; memset(vis,0,sizeof(vis)); vis[0] = 1; for(int i = 0; i<=n; i++) cast[i] = map[0][i]; for(int i = 0; i<=n; i++) { minn = INF; for(int j = 0; j<=n; j++) { if(cast[j]
<< -1 << endl; else cout << cast[s] << endl; } //cout << "Hello world!" << endl; return 0;}

 

转载地址:http://pewof.baihongyu.com/

你可能感兴趣的文章
设计模式深入浅出-----策略模式(Strategy Pattern)
查看>>
UML的组成与UML建模一般流程
查看>>
项目管理----项目进度管理
查看>>
项目管理----项目范围管理
查看>>
SQL性能优化
查看>>
SQL表连接查询(inner join、full join、left join、right join)
查看>>
SQL语言学习心得
查看>>
有趣的编程----控制自己电脑的CPU
查看>>
Windows程序运行原理
查看>>
图解JAVA中Spring Aop作用
查看>>
组件化、模块化、集中式、分布式、服务化、面向服务的架构、微服务架构
查看>>
分布式服务架构与微服务架构概念的区别与联系是怎样的
查看>>
微服务架构的优势与不足
查看>>
微服务架构中的进程间通信
查看>>
选择微服务部署策略
查看>>
Docker 在分布式和大数据框架中的应用
查看>>
javaweb学习总结——获得MySQL数据库自动生成的主键
查看>>
【zabbix教程三】——centos7 安装zabbix客户端并监控
查看>>
SpringMVC
查看>>
多线程
查看>>