[C++] PAT 1030 Travel Plan (30分)

博客介绍了PAT 1030题目的样例输入和输出,并探讨了如何解决该旅行计划问题。通过使用优化的Dijkstra算法,找到从起点到目标节点的所有最短路径中成本最低的一条。
摘要由CSDN通过智能技术生成

在这里插入图片描述

Sample Input:

4 5 0 3
0 1 1 20
1 3 2 30
0 3 4 10
0 2 2 20
2 3 1 20

Sample Output:

0 2 3 3 40

题解:

相对于普通的Dijsktra,将parent[]数组,变为了vector<int> pre[],这样就可以根据目标节点,递归遍历其所有的最短路径,最终找到价格最小的那条路径

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct cmp{
   
	bool operator()(pair<int,int> &a,pair<int,int> &b){
   

		return a.second > b.second;
	
	}
};


const int MAXV = 510;
const int INF  = 100000;

int n,m,s,d,G[MAXV][MAXV],G_value[MAXV][MAXV];
int dis[MAXV];
vector<int> pre[MAXV];
vector<int> short_path,temp_short_path;
int opValue = INF,value = INF;
priority_queue
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值