HDU 2680 Choose the best route 最短路
来源:互联网 发布:淘宝人工客服在哪里 编辑:程序博客网 时间:2024/06/05 16:12
Choose the best route
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 144 Accepted Submission(s): 57
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=
#include<iostream>#include<string.h>#include<stdio.h>#include<vector>#include<queue>using namespace std;struct road{ int end; int cost; friend bool operator < (const road &a,const road &b) { return a.cost>b.cost; }};priority_queue<road> que;vector<road> v[1005];bool vis[1005];int main(){ int n,m,i,j; int a,b,c; int sta; road p; int E; while(~scanf("%d%d%d",&n,&m,&E)) { E++; memset(vis,0,sizeof(vis)); for(i=0;i<1005;i++) v[i].clear(); for(i=0;i<m;i++) { scanf("%d%d%d",&a,&b,&c); a++; b++; p.end=b; p.cost=c; v[a].push_back(p); } scanf("%d",&m); for(i=0;i<m;i++) { scanf("%d",&sta); sta++; p.end=sta; p.cost=0; v[0].push_back(p); } p.end=0; p.cost=0; que.push(p); road now,next; int falg=0; while(!que.empty()) { now=que.top(); que.pop(); if(vis[now.end]) continue; vis[now.end]=true; if(now.end==E) { falg=1; break; } int d=v[now.end].size(); for(i=0;i<d;i++) { next.end=v[now.end][i].end; if(vis[next.end]) continue; next.cost=v[now.end][i].cost+now.cost; que.push(next); } } if(falg) cout<<now.cost<<endl; else cout<<"-1"<<endl; while(!que.empty()) { que.pop(); } } return 0;}
- hdu 2680-Choose the best route最短路dijkstra
- HDU 2680 Choose the best route 变形最短路 DIJKSTRA
- HDU 2680Choose the best route(dijk最短路)
- hdu 2680 Choose the best route(最短路)
- hdu 2680 Choose the best route(最短路dijkstra(有重边))
- hdu 2680 Choose the best route 最短路
- HDU 2680 Choose the best route 最短路
- HDU-2680 Choose the best route(最短路[Dijkstra])
- hdu-2680Choose the best route (dijkstra求最短路)
- HDU 2680Choose the best route (最短路+迪杰斯特拉)
- #HDU 2680 Choose the best route 【SPFA最短路】
- hdu 2680 Choose the best route(最短路)
- HDU 2680 Choose the best route(最短路,反向)
- HDU 2680 Choose the best route 最短路
- HDU 2680 Choose the best route 最短路
- HDU 2680 Choose the best route多源点最短路
- hdu 2680 Choose the best route 最短路 解题报告
- HDU 2680-Choose the best route-最短路+超级源点
- 织梦DedeCms列表{dede:list}标签实现按文章权重weig
- myeclipse提示内存不足解决 (转)
- 在linux系统下,创建oracle数据库表空间、用户权限操作功能
- 一次网络请求的流程
- Android中MVP模式与MVC模式比较(含示例)
- HDU 2680 Choose the best route 最短路
- 141. Linked List Cycle
- WEB前端模块化基础知识
- uC/OS-II任务就绪表及任务调度
- Non-terminating decimal expansion问题重新温习BigDecimal roundMode
- [已解决]junit.framework.AssertionFailedError: No tests found in com.wbm.app.business.NeedLoginTestCase
- Hadoop伪分布式环境搭建(二)
- Java 类与对象
- J-Link烧写STM32失败的问题