[最短路]POJ 3594 Escort of Dr. Who How#最短路+枚举

这是一个使用最短路算法解决POJ 3594问题的C++代码实现,题目要求找到从起点到终点的最短时间路径,考虑到路径的时间限制,需要对最优起始时间进行枚举。代码中使用了优先队列和Dijkstra算法来找出最短路径。
摘要由CSDN通过智能技术生成
/**
[最短路]poj 3594
求起点到终点的最短时间耗费,每条路限制只在一定的时间范围内可以通行。
最优起始时间不确定,故需要枚举。
*/
#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

#define INF 100000000
#define N 101
struct node
{
    int u,d,s,e;
    node(int a = 0,int b = 0,int c = 0,int f = 0)
    {
        u = a;
        d = b;
        s = c;
        e = f;
    }

}p;
vector<node> g[N];
int vis[N],d[N],n,m,src,dst;
bool operator<(const node &pp,const node &pt)
{
    return pp.d > pt.d;
}
int dij(int t)
{
    int i;
    memset(vis,0,sizeof(vis));
    for(i = 0; i <= n; ++i)
        d[i] = INF;
    p = node(src,t);
    d[src] = t;
    priority_queue<node> que;
    que.push(p);
    int u,v,w;
    while(!que.empty())
    {
        p = que.top();
        que.pop();
        u = p.u;
        if(vis[u])
       
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值