一本通 1261:【例9.5】城市交通路网

城市交通路网

最短路 + 路径输出


Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
//Mystery_Sky
//
#define M 1000100
#define INF 0x3f3f3f3f
struct Edge{
    int to, next, w;
}edge[M];

int n, m;
int map[5000][5000];
int head[M], cnt, dis[M], vis[M];
inline void add_edge(int u, int v, int w)
{
    edge[++cnt].to = v;
    edge[cnt].next = head[u];
    edge[cnt].w = w;
    head[u] = cnt;
}

struct node {
    int dis;
    int pos;
    inline bool operator <(const node &x) const{
        return x.dis < dis;
    }
};
priority_queue <node> q;
inline void dijkstra()
{
    memset(dis, INF, sizeof(dis));
    dis[1] = 0;
    q.push((node){0, 1});
    while(!q.empty()) {
        node top = q.top();
        q.pop();
        int x = top.pos;
        if(vis[x]) continue;
        vis[x] = 1;
        for(int i = head[x]; i; i = edge[i].next) {
            int y = edge[i].to;
            if(dis[y] > dis[x] + edge[i].w) {
                dis[y] = dis[x] + edge[i].w;
                if(!vis[y]) q.push((node){dis[y], y}); 
            }
        }
    } 
}

void print(int i) {
    if(i == 1) return;
    for(int k = 1; k <= n; k++) {
        if(dis[k] + map[k][i] == dis[i]) {
            print(k);
            printf("%d ", k);
            return;
        }
    }
}

int main() {
    scanf("%d", &n);
    int a;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++) {
            scanf("%d", &map[i][j]);
            if(map[i][j]) add_edge(i, j, map[i][j]);
        }
    dijkstra();
    printf("minlong=%d\n", dis[n]);
    print(n);
    printf("%d\n", n);
    return 0;
}

转载于:https://www.cnblogs.com/Benjamin-cpp/p/10995041.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PowerPCB 9.5是一个电路板设计软件。它具有强大的功能,可以帮助用户轻松地创建和修改复杂的电路板设计。 PowerPCB 9.5的主要特点包括以下几个方面: 1. 用户友好的界面:PowerPCB 9.5具有直观的界面设计,使用户能够快速上手并进行电路板设计。它提供了一系列易于使用的工具和选项,方便用户进行布局和布线等操作。 2. 强大的设计功能:PowerPCB 9.5具有丰富的设计功能,能够满足用户对复杂电路板设计的各种需求。它支持多层电路板设计、自动布线、信号完整性分析等功能,能够帮助用户快速有效地完成设计任务。 3. 模块化设计:PowerPCB 9.5支持模块化设计,可以将复杂的电路板设计拆分为多个模块进行独立设计。这样可以提高设计效率,便于设计团队的分工合作。 4. 丰富的元件库:PowerPCB 9.5内置了丰富的元件库,包括常用的电子元件和封装。用户可以根据需要快速选择合适的元件,并进行布局和布线。 5. 与其他工具的集成:PowerPCB 9.5可以与其他常用的电子设计自动化工具进行集成,如原理图设计软件和仿真工具等。这样可以在设计过程中实现更加全面的功能和效果。 总的来说,PowerPCB 9.5是一款功能强大的电路板设计软件,它可以帮助用户轻松地创建和修改复杂的电路板设计。它具有直观的界面设计、丰富的设计功能、模块化设计、丰富的元件库以及与其他工具的集成等特点,能够提高设计效率并满足不同用户的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值