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 ...
随机推荐
- CF528D Fuzzy Search 字符串匹配+FFT
题意: DNA序列,在母串s中匹配模式串t,对于s中每个位置i,只要s[i-k]到s[i+k]中有c就认为匹配了c.求有多少个位置匹配了t. 分析: 这个字符串匹配的方式,什么kmp,各种自动机都不灵 ...
- Uva 12325 Zombie's Treasure Chest (贪心,分类讨论)
题意: 你有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号的整数.你的任务是最多能装多少价值的宝物? 分析: 分类枚举, ...
- POJ 3522 Slim Span (Kruskal枚举最小边)
题意: 求出最小生成树中最大边与最小边差距的最小值. 分析: 排序,枚举最小边, 用最小边构造最小生成树, 没法构造了就退出 #include <stdio.h> #include < ...
- nginx.conf的完整配置说明
#用户 用户组 user www www; #工作进程,根据硬件调整,有人说几核cpu,就配几个,我觉得可以多一点 worker_processes 5: #错误日志 error_log logs/e ...
- ul标签中,li标签的移除、属性值获取
- Go 方法和接收者
package main import ( "fmt" ) //面向对象 //go仅支持封装,不支持继承和多态 //go语言中没有class,只要struct //不论地址还是结构 ...
- [luoguP2679] 子串(DP)
传送门 气死我了,自己YY的方法只能得70分. 一个下午都在搞这道题. 至于正解,真的不想写了. 请移步 here #include <cstdio> #define M 201 #def ...
- @Temporal()注解的使用
数据库的字段类型有date.time.datetime而Temporal注解的作用就是帮Java的Date类型进行格式化,一共有三种注解值: 第一种:@Temporal(TemporalType.DA ...
- 斗地主(codevs 4610)
题目描述 Description 牛牛最近迷上了一种叫斗地主的扑克游戏. 斗地主是一种使用黑桃.红心.梅花.方片的 A 到 K 加上大小王的共 54 张牌来进行的扑克牌游戏.在斗地主中, 牌的大小关系 ...
- [Baltic2007]序列问题Sequence
Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 1002 Solved: 535[Submit][Status][Discuss] Descriptio ...