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 ...
随机推荐
- 教你学会Linux/Unix下的vi文本编辑器
vi编辑器是Unix/Linux系统管理员必须学会使用的编辑器.看了不少关于vi的资料,终于得到这个总结. 首先,记住vi编辑器的两个模式:1.命令模式 2.编辑模式. 在一个UNIX/Linux的s ...
- 【简●解】[ZJOI2005]午餐
[简●解][ZJOI2005]午餐 [关键词] \(DP\) 排序/贪心 [分析] 首先,一个很明显的贪心思路,就是吃的慢的人先打饭.所以把数据按吃饭时间从大到小排一遍序. 根据\(dp\)的尿性,比 ...
- 3. COLLATIONS
3. COLLATIONS 表COLLATIONS提供有关每个字符集排序规则的信息.下表中SHOW Name对应SHOW COLLATION. INFORMATION_SCHEMA Name SHOW ...
- 如何用纯 CSS 创作一种文字断开的交互特效
效果预览 在线演示 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. https://codepen.io/zhang-ou/pen/LmjNgL 可交互视频教程 此视 ...
- mac 监控文件变化并重启php
自己撸一个框架,需要监控代码变化 安装fswatch brew install fswatch shell重启PHP脚本reload.sh #!/bin/sh do ps -ef | grep php ...
- Python数据可视化库-Matplotlib(一)
今天我们来学习一下python的数据可视化库,Matplotlib,是一个Python的2D绘图库 通过这个库,开发者可以仅需要几行代码,便可以生成绘图,直方图,功率图,条形图,错误图,散点图等等 废 ...
- CentOS 6.5 x64 安装MySql 5.6
1.检测是否已经安装MySQL,输入以下命令 rpm -qa | grep mysql 如果存在,我们输入以下命令来删除 //强力删除 rpm -e --nodeps mysql 2.安装前环境准备 ...
- POJ 3122 pie (二分法)
Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have ...
- POJ 1414 Life Line(搜索)
题意: 给定一块正三角形棋盘,然后给定一些棋子和空位,棋子序号为a(1<=a<=9),group的定义是相邻序号一样的棋子. 然后到C(1<=N<=9)棋手在空位放上自己序号C ...
- 【MFC】利用MFC写一个计时器小程序
1整体设计 创建对话框程序,并且设计对话框相关控件如图 相应的ID和对应的成员变量如图: 我的想法是这样的,只读属性的编辑框添加有CString类型的成员变量(如s_hour),在xxxDlg.h里另 ...