#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)的更多相关文章

  1. PAT1030 Travel Plan (30)---DFS

    (一)题意 题目链接:https://www.patest.cn/contests/pat-a-practise/1030 1030. Travel Plan (30) A traveler's ma ...

  2. PAT-1030 Travel Plan (30 分) 最短路最小边权 堆优化dijkstra+DFS

    PAT 1030 最短路最小边权 堆优化dijkstra+DFS 1030 Travel Plan (30 分) A traveler's map gives the distances betwee ...

  3. [图算法] 1030. Travel Plan (30)

    1030. Travel Plan (30) A traveler's map gives the distances between cities along the highways, toget ...

  4. 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 ...

  5. PAT1030. Travel Plan

    //晴神模板,dij+dfs,貌似最近几年PAT的的图论大体都这么干的,现在还在套用摸板阶段....估计把这及格图论题题搞完,dij,dfs,并查集就掌握差不多了(模板还差不多)为何bfs能自己干出来 ...

  6. 1030. Travel Plan (30)

    时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A traveler's map gives the dista ...

  7. 1030 Travel Plan (30)(30 分)

    A traveler's map gives the distances between cities along the highways, together with the cost of ea ...

  8. 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 ...

  9. 1030 Travel Plan (30分)(dijkstra 具有多种决定因素)

    A traveler's map gives the distances between cities along the highways, together with the cost of ea ...

随机推荐

  1. poj1026(置换找循环节)

    找到循环节,然后对应的变换 Cipher Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20377   Accepted:  ...

  2. 【BZOJ1912】[Apio2010]patrol 巡逻 树形DP

    [BZOJ1912][Apio2010]patrol 巡逻 Description Input 第一行包含两个整数 n, K(1 ≤ K ≤ 2).接下来 n – 1行,每行两个整数 a, b, 表示 ...

  3. MySQL (时间)日期相减取天数

    select TO_DAYS(str_to_date('12/1/2001 12:00:00 AM','%m/%d/%Y')) -TO_DAYS(str_to_date('11/28/2001 12: ...

  4. 【转】 通过VMLibrary在client partition上安装AIX全程实录

    现场实录,应该对新手有所帮助,因为本人就是新手...最近一段时间跟Linux无缘,都是在和PowerVM打交道,博文更新慢,不赖我,哈哈本文参考链接:AIX Migration with File-B ...

  5. 部署samba

    1.首先需要关闭防火墙 2,创建用户名 3.IP地址配置ping下能不能成功 4.yum install samba -y 进行软件包的安装 5,vim修改.etc/samba/smb.conf/的配 ...

  6. corethink功能模块探索开发(三)让这个模块可见

    感觉corethink把thinkphp的思想复用到淋漓尽致. 1.把opencmf.php文件配置好了后台该模块的菜单就能在安装后自动读取(分析好父子关系,否则页面死循环,apache资源占用率10 ...

  7. java.lang.NoClassDefFoundError: org/springframework/expression/PropertyAccessor

    这个异常原因种类不一,网上有各个版本,本人的是因为缺少了spring-expression-3.2.1.RELEASE.jar 2015-9-18 23:19:11 org.apache.catali ...

  8. 对称加密,API加密

    用于API加密,双方约定好signature_key对请求的参数进行处理 处理步骤如下 把请求的数据生成为key=>value的形式,然后拼接生成arg_key arg_key加上双方约定的si ...

  9. iOS 视频全屏功能 学习

    项目中,也写过类似"视频全屏"的功能, 前一阵子读到今日头条 的一篇技术文章,详细介绍三种旋转方法差异优劣最终择取.文章从技术角度看写的非常好,从用户角度看,也用过多家有视频功能的 ...

  10. WEB网页专业词汇 汇总

    Accessibility  可访问性 accessor properties 存取器属性 addition 加法 aggregate 聚合 alphabetical order 字母表顺序 Anch ...