P4779【模板】单源最短路径(标准版)(dij)
发布日期:2021-06-27 21:40:29 浏览次数:3 分类:技术文章

本文共 580 字,大约阅读时间需要 1 分钟。

单源最短路径

在这里插入图片描述
在这里插入图片描述

解题思路

dij模板

AC代码

#include
#include
#include
using namespace std;int n,m,s,tot,c[100005],head[100005];long long d[100005];priority_queue
> q;//队列struct node{
int to,next,z;}a[200005];void add(int x,int y,int z){
a[++tot]=(node){
y,head[x],z}; head[x]=tot;}void dij()//dij{
memset(d,0x7f,sizeof(d)); d[s]=0; q.push(make_pair(0,s)); while(!q.empty()) {
int x=q.top().second; q.pop(); if(c[x])continue; c[x]=1; for(int i=head[x];i;i=a[i].next) if(!c[a[i].to]&&d[x]+1ll*a[i].z

谢谢

转载地址:https://blog.csdn.net/weixin_45524309/article/details/117082795 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:判断负环(spfa)
下一篇:构造完全图(最小生成树)

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年03月30日 03时27分07秒