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 ...
随机推荐
- install docker-ce for ubuntu
may need login vpn first docker-ce for ubuntu chinese version docker-ce for ubuntu
- java指令详解
Java是通过java虚拟机来装载和执行编译文件(class文件)的,java虚拟机通过命令java option 来启动,-option为虚拟机参数,通过这些参数可对虚拟机的运行状态进行调整. 一. ...
- ArchLinux 安装笔记
前言 在开始之前,请在心中默念三遍: Arch Linux 是世界上最好的发行版, 我一定能掌握她. 环境 VM ware + UEFI + 500G 虚拟磁盘 + 2G 内存 + 桥接网络 下载镜像 ...
- Python Tornado简单的http request
这是关于chunk encoding传输以前相关传输编码的处理.没有做压缩解码的处理. import tornado.ioloop import tornado.iostream import soc ...
- BZOJ 1412: [ZJOI2009]狼和羊的故事【网络流】
Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! O ...
- C++中,什么叫类,结构,联合?
在C++中 class 和 struct 本质上一样 可以互用class的成员默认是private的,struct的成员默认是public的但一般习惯把成员变量隐藏的用class申明, 成员变量可以公 ...
- hud 2073
#include<stdio.h> #include<math.h> int main() { int i,j,k,n,m,t; double a]; a; for;i++) ...
- bzoj 1700 Problem Solving 解题 dp
[Usaco2007 Jan]Problem Solving 解题 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 492 Solved: 288[Sub ...
- HDU 1402 大数乘法 FFT、NTT
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- POJ 2438 哈密顿回路
Children's Dining Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4730 Accepted: 754 ...