Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 10761    Accepted Submission(s): 3484

Problem Description
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 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
 
Sample Output
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的更多相关文章

  1. hdu 2680 Choose the best route

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki ...

  2. 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 ...

  3. Choose the best route(最短路)dijk

    http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Time Limit: 2000/1000 MS (Java/ ...

  4. 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 ...

  5. 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 ( ...

  6. hdu-2680 Choose the best route(最短路)

    题目链接: Choose the best route Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K ( ...

  7. 最短路问题-- Dijkstra Choose the best route

    Choose the best route Problem Description One day , Kiki wants to visit one of her friends. As she i ...

  8. hdoj 2680 choose the best route

    Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsicknes ...

  9. HDU 2680 Choose the best route(SPFA)

    Problem DescriptionOne day , Kiki wants to visit one of her friends. As she is liable to carsickness ...

随机推荐

  1. Java 编程下 Eclipse/myeclipse 如何设置单行代码显示的最大宽度

    http://www.cnblogs.com/sunzn/archive/2013/03/30/2990191.html 或 http://zhidao.baidu.com/link?url=67uy ...

  2. Map与对象关系的思考之P1563玩具谜题

    P1563 玩具谜题 结论: map在一些情况有种"对象"的意味,在JSON中,对象可以用K-V格式存储:mybatis中参数是map或者对象都可以实现解析...k-v格式的数据存 ...

  3. bzoj2588 counting on a tree

    题目不难,树上可持久化数据结构. 帖代码: #include<cstdio> #include<algorithm> using namespace std; #define ...

  4. [POJ] 2223 Muddy Fields

    Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11490 Accepted: 4270 Description Rain has ...

  5. java+selenium+maven+IntelliJ IDEA 搭建简单的UI自动化测试环境

    1. 用IntelliJ IDEA新建一个maven工程 2. 在pom.xml中添加依赖: <dependency> <groupId>org.seleniumhq.sele ...

  6. IP封包协议头/TCP协议头/TCP3次握手/TCP4次挥手/UDP协议头/ICMP协议头/HTTP协议(请求报文和响应报文)/IP地址/子网掩码(划分子网)/路由概念/MAC封包格式

    IP协议头IP包头格式: 1.版本号:4个bit,用来标识IP版本号.这个4位字段的值设置为二进制的0100表示IPv4,设置为0110表示IPv6.目前使用的IP协议版本号是4. 2.首部长度:4个 ...

  7. Android开发——后台获取用户点击位置坐标(可获取用户支付宝密码)

    1. getevent命令 我们首先是根据adb shell getevent命令获取到被点击位置的信息. 这里要说明的是,不同的手机手机获得的点击输出是不一样的.以我的真机为例,输出如下 本文原创, ...

  8. 洛谷 P1938 [USACO09NOV] 找工就业Job Hunt

    这道题可以说是一个复活SPFA的题 因为数据比较小,SPFA也比较简单 那就复习(复读)一次SPFA吧 #include<iostream> #include<cstdio> ...

  9. 【01】在 Github 上编辑代码

    [01]在 Github 上编辑代码 当你使用 GitHub,看一些文件(任何的文本文件或者仓库),能看到一个顶部右侧有一个小铅笔图标.点击即可编辑文档. 完成后,按照提示点击「Propose fil ...

  10. Fiddler抓包-工具介绍(request和response)

    from:https://www.cnblogs.com/yoyoketang/p/6731121.html 本篇简单的介绍下fiddler界面的几块区域,以及各自区域到底是干什么用的,以便于各好的掌 ...