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 ...
随机推荐
- ios代码实现时间设置NSDate
本文转载至 http://www.baidu.com/link?url=dcQWiL1FD_She6P4RM2IvEeJas0_gtG3LkRNTV5H87X0AyKCHvwYjBz2hdcB2JVp ...
- hdu 5068(线段树+矩阵乘法)
矩阵乘法来进行所有路径的运算, 线段树来查询修改. 关键还是矩阵乘法的结合律. Harry And Math Teacher Time Limit: 5000/3000 MS (Java/Others ...
- hihoCoder 1549 或运算和
#1549 : 或运算和 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定N个数A1...AN (0 <= Ai < 220) 和一个正整数K,我们用An ...
- Delphi运算符及优先级
单目运算符 (最高优先级) @ 取变量或函数的地址(返回一个指针) not 逻辑取反或按位取反 乘除及按位运算符 * 相乘或集合交集 / 浮点相除 div 整数相除 mod 取模 (整数相除的余数) ...
- 理解CSS3属性transition
一.说明 1.1 定义和用法 transition 属性是一个简写属性,用于设置四个过渡属性: transition-property:规定设置过渡效果的CSS属性的名称. transition-du ...
- Django分发控制器urls--白话聊Django系列
开始前,先上一张图,让理解Django内部的处理流程,从图中我们可以知道Django内部使用MTV架构,那今天讲的第一个部分就是控制器,在Tornado框架中叫做路由系统,负责把url映射到相应的处理 ...
- AngularCli项目中添加字体图标(Font)详解
本文主要讲如何在AngularCli生成的项目中使用字体图标. 一 SVG图标准备 将需要转换为字体图标的图片转换为SVG格式. 这个让项目视觉设计师搞定即可. 二 SVG图标转Font 可以通过Ic ...
- LinuxCentos系统安装Mariadb过程记录
MariaDB数据库简介 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可. 开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜 ...
- Python打印一个等边三角形
如图所示: * *** ***** ******* ********* #想要几层就输入数字几, num = int(input('请输入一个奇数数字:')) for i in range(num,0 ...
- 启动hive --service metastore &出现Missing Hive Execution Jar: /opt/apache-hive-1.2.0-bin//lib/hive-exec-*.jar
原因:出现上述问题通常是运行hive 在bin/目录下的脚本所致. 解决办法:就是让HIVE_HOME变量指向hive-trunk/build/dist目录,将$HIVE_HOME/bin添加到PAT ...