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 ...
随机推荐
- IIPP迷你项目(二)"Guess the Number!"
本来这个程序是早就编完了的,一直没时间发布博客.时至今日已时隔多天,也算是复习一下事件驱动型编程的过程吧. 1 事件驱动型编程 本质上这次的作业是披着猜数字皮的图形化界面编程,好在 simplegui ...
- 如何自己实现一套EasyNVR这样的无插件流媒体服务器
EasyNVR流媒体解决方案 EasyNVR能够通过简单的网络摄像机通道配置,将传统监控行业里面的高清网络摄像机IP Camera.NVR等具有RTSP协议输出的设备接入到EasyNVR,EasyNV ...
- jQuery实现局部刷新页面数据绑定
今天遇到了一个问题:怎么样才能做到只刷新页面中的Repeater控件中的数据,在不用UploadPannel的情况下? 试了好多方法,无意间在看jquery文件时发现,使用load()方法即可解决此问 ...
- Selenium:常见web UI元素操作及API使用
链接(link) <div> <p>链接 link</p> <a href="www.cnblogs.com/tankxiao">小 ...
- ffmpeg参数使用说明2
附录一(ffmpeg参数说明): [参数] [说明] [示例] -i "路径" 指定需要转换的文件路径 -i "C:\nba.wmv" -y 覆盖输出文件,即如 ...
- Linux中变量测试与内容替换
- 印象笔记windows端-快捷键大全
作为印象笔记粉,当然要多掌握些快捷键,提高办公效率. 补: ctrl + shift + , 光标内字体变小 ctrl + shitf + . 光标内字体变大
- MFC中修改程序图标
在使用MFC时,我们经常需要修改我们得到的exe文件的图标.如:写一个随机画圆的小程序,我们就希望该程序的图标是个圆或者是和圆有关的图标.所以,在这里我就记录一下我修改图标的步骤. 顺便提一下,我使用 ...
- 方阵行列式并行化计算(OpenMP,MPI),并计算加速比
00][100].在创建方阵时,方阵的阶数N(N<100)由外部输入.然后用两层"for循环"来给方阵 p左上角 N×N个位置赋值.具体实现如下: /* * 定义矩阵阶数N ...
- CSS中input输入框点击时去掉外边框方法【outline:medium;】----CSS学习
CSS 中添加 outline:medium; JS 控制焦点: $("#CUSTOM_PHONE").focus(function(event){ // this.attr(&q ...