#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. Linux 进程间通信(一)(经典IPC:消息队列、信号量、共享存储)

    有3种称作XSI IPC的IPC:消息队列.信号量.共享存储.这种类型的IPC有如下共同的特性. 每个内核中的IPC都用一个非负整数标志.标识符是IPC对象的内部名称,为了使多个合作进程能够在同一IP ...

  2. cocos2d-x设计模式发掘之一:单例模式

       作者: firedragonpzy  原地址:http://www.firedragonpzy.com.cn/index.php/archives/1781 本系列文章我将和大家一起来发掘coc ...

  3. 1366 贫富差距(floyed)

    1366 贫富差距 题目来源: TopCoder 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个国家有N个公民,标记为0,1,2,...,N-1,每个公民有一 ...

  4. Kubectl工具常用命令

    创建namesapce kubectl create namespace {name} 注意:name只能为小写字母.数字和-的组合,且开头结尾为字母,一般格式为my-name 123-abc等. 创 ...

  5. django database relations

    注意Django的生成的默认api from django.db import models class Place(models.Model): ''' pass class Restaurant( ...

  6. Constructor Acquires, Destructor Releases Resource Acquisition Is Initialization

    w https://zh.wikipedia.org/wiki/RAII RAII要求,资源的有效期与持有资源的对象的生命期严格绑定,即由对象的构造函数完成资源的分配(获取),同时由析构函数完成资源的 ...

  7. dev 小问题列表

    1. MemoEdit > Lines Text lines are separated by line feed and carriage return characters ("\ ...

  8. 比较运算符compareTo()、equals()、==之间的区别

    前言 首先再次强调hashcode (==)和equals的真正含义(我记得以前有人会说,equals是判断对象内容,hashcode是判断是否相等之类): equals:是否同一个对象实例.注意,是 ...

  9. VCL控件组件大都应该重载TWinControl的虚函数WndProc来进行处理窗口消息的工作

    TWinControl的构造函数中会调用MakeObjectInstance并且传递MainWndProc作为窗口消息处理函数,而MainWndProc则会调用虚函数WndProc来处理窗口消息.留个 ...

  10. 解决github访问慢和clone慢解决方案

    在http://tool.chinaz.com/dns/ 这个网站输入github.com 打开cmd ping各个服务器ip地址,看看哪个比较好 windows下C:\Windows\System3 ...