PAT1030. Travel Plan (30)
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
int n,m,s,d;
int cityMap[500][500];
int costMap[500][500];
#define INF numeric_limits<int>::max()
int dp[500];
int vis[500];
int costDp[500];
vector<int> route[500];
void djkstra(){
for(int i=0;i<n;i++) dp[i]=INF;
dp[s]=0;route[s].push_back(s);
for(int i=0;i<n;i++){
int x,m=INF;
for(int j=0;j<n;j++){
if(!vis[j]&&dp[j]<m){
m=dp[x=j];
}
}
vis[x]=1;
for(int j=0;j<n;j++){
if(cityMap[x][j]!=0){
if(dp[j]>dp[x]+cityMap[x][j]){
dp[j]=dp[x]+cityMap[x][j];
costDp[j]=costDp[x]+costMap[x][j];
route[j]=route[x];
route[j].push_back(j);
}else if(dp[j]==dp[x]+cityMap[x][j]){
if(costDp[j]>(costDp[x]+costMap[x][j])){
costDp[j]=costDp[x]+costMap[x][j];
route[j]=route[x];
route[j].push_back(j);
}
}
}
}
}
}
int main(){
cin>>n>>m>>s>>d;
int c1,c2;
for(int i=0;i<m;i++){
cin>>c1>>c2;
cin>>cityMap[c1][c2]>>costMap[c1][c2];
cityMap[c2][c1]=cityMap[c1][c2];
costMap[c2][c1]=costMap[c1][c2];
}
djkstra();
vector<int> tmp=route[d];
vector<int>::iterator ii=tmp.begin();
while(ii!=tmp.end()){
cout<<(*ii)<<" ";
ii++;
}
cout<<dp[d]<<" "<<costDp[d];
return 0;
}
PAT1030. Travel Plan (30)的更多相关文章
- PAT1030 Travel Plan (30)---DFS
(一)题意 题目链接:https://www.patest.cn/contests/pat-a-practise/1030 1030. Travel Plan (30) A traveler's ma ...
- PAT-1030 Travel Plan (30 分) 最短路最小边权 堆优化dijkstra+DFS
PAT 1030 最短路最小边权 堆优化dijkstra+DFS 1030 Travel Plan (30 分) A traveler's map gives the distances betwee ...
- [图算法] 1030. Travel Plan (30)
1030. Travel Plan (30) A traveler's map gives the distances between cities along the highways, toget ...
- PAT 甲级 1030 Travel Plan (30 分)(dijstra,较简单,但要注意是从0到n-1)
1030 Travel Plan (30 分) A traveler's map gives the distances between cities along the highways, to ...
- PAT1030. Travel Plan
//晴神模板,dij+dfs,貌似最近几年PAT的的图论大体都这么干的,现在还在套用摸板阶段....估计把这及格图论题题搞完,dij,dfs,并查集就掌握差不多了(模板还差不多)为何bfs能自己干出来 ...
- 1030. Travel Plan (30)
时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A traveler's map gives the dista ...
- 1030 Travel Plan (30)(30 分)
A traveler's map gives the distances between cities along the highways, together with the cost of ea ...
- PAT Advanced 1030 Travel Plan (30) [Dijkstra算法 + DFS,最短路径,边权]
题目 A traveler's map gives the distances between cities along the highways, together with the cost of ...
- 1030 Travel Plan (30分)(dijkstra 具有多种决定因素)
A traveler's map gives the distances between cities along the highways, together with the cost of ea ...
随机推荐
- jmeter 响应数据更换显示类型(json、html、text)
.默认情况下是Text格式 2.修改为json格式显示
- boost::lockfree::queue
#include <boost/thread/thread.hpp> #include <boost/lockfree/queue.hpp> #include <iost ...
- joisino's travel
D - joisino's travel Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement T ...
- Constructor Acquires, Destructor Releases Resource Acquisition Is Initialization
w https://zh.wikipedia.org/wiki/RAII RAII要求,资源的有效期与持有资源的对象的生命期严格绑定,即由对象的构造函数完成资源的分配(获取),同时由析构函数完成资源的 ...
- 全局enter回车键js
js实现敲回车键触发事件 document.onkeydown = function(e){ var ev = document.all ? window.event : e; ){ alert(&q ...
- while循环。for循环
1.while循环 基本循环格式 while 条件 : # 循环体 # 如果条件为真,那么循环体则执行 # 如果条件为假,那么循环体不执行 break:退出本层循环. continue:退出本次循环, ...
- SPDY
转载SPDY 是什么 SPDY 是 Google 开发的基于传输控制协议 (TCP) 的应用层协议 ,开发组正在推动 SPDY 成为正式标准(现为互联网草案).SPDY 协议旨在通过压缩.多路复用和优 ...
- app开发流程有哪些
app开发流程是需求方和供求方相互协调的过程,一般分为需求分析.功能设计.功能实现.项目测试.上线等几个步骤,下面我们就来一起看看ytkah团队进行app开发各个流程主要做哪些事情,让您对app开发设 ...
- sublime使用心得
1.ctrl + shift +p 命令面板 ---> toggle_side_bar 2.ctrl + shift +p 命令面板 --->reindent lines 3.ctrl + ...
- JS中原型链的理解
new操作符具体干了什么呢?其实很简单,就干了三件事情. var obj = {}; obj.__proto__ = Base.prototype; Base.call(obj); 第一行,我们创建了 ...