当前位置: 首页 > news >正文

第一次学dij qwq(p4779

洛谷p4479

第一学dijkstra耶qwq

#include<bits/stdc++.h>
using namespace std;
struct edge{int to,v,next,w;
}a[500005];
struct node{int w,g;friend bool operator<(node a,node b){return a.w>b.w;}
}tmp;
int dis[100005],h[500005],b[100005];
int n,m,s,cnt;
priority_queue<node> q;
void dij(){for(int i=1;i<=n;i++) dis[i]=0x3f3f3f3f;dis[s]=0;tmp.g=s; tmp.w=0;q.push(tmp);while(!q.empty()){int u=q.top().g;q.pop();if(b[u]==1) continue;b[u]=1;for(int i=h[u];i;i=a[i].next){if(dis[a[i].to]>(long long)dis[u]+a[i].v){dis[a[i].to]=dis[u]+a[i].v;tmp.g=a[i].to; tmp.w=dis[a[i].to];q.push(tmp);} }}
}
int main(){cin>>n>>m>>s;int u,v,w;for(int i=1;i<=m;i++){cin>>u>>v>>w;a[i].to=v;a[i].v=w;a[i].next=h[u];h[u]=i; }dij();for(int i=1;i<=n;i++){cout<<dis[i]<<" ";}return 0;
}
http://www.hskmm.com/?act=detail&tid=406

相关文章:

  • 1
  • 2025—2026 赛季记录
  • AI编程新范式:从Coding到Vibe Coding,你准备好了吗?
  • Ubuntu 安装搜狗输入法
  • KD-Tree
  • yyjj
  • 今日随笔
  • 摆放类状压DP基础题
  • 使用 Visual Studio 2022 创建动态库和静态库 - Invinc
  • 软件
  • Laravel PHP 忘记密码如何重置(创建新管理员账号)
  • 打工人必看!昆工MBA“项目管理”杀疯了
  • 第一章 逻辑代数基础 - Wisdom
  • DVectorT虐哭ListT
  • 201912_BUUCTF_Base64隐写
  • 软考达人-案例分析
  • kettle插件-sqlserver cdc插件,从sqlserver获取实时数据so easy,早早下班
  • golang netpoll 底层原理
  • manim如何按绝对时间管理动画
  • MATLAB R2025a安装教程和资源(中文版)
  • Xmanager Power Suite使用教程 - Invinc
  • try hack me.md
  • Snapshot-based State Replication 基于快照的状态复制网络框架,快照同步
  • Transformer通俗讲解
  • Ubuntu 安装微信
  • Ubuntu 安装截图软件 flameshot
  • Kali连接postgreSQL失败(已解决)
  • 主存储器和cpu的链接
  • 7. LangChain4j + 记忆缓存详细说明 - Rainbow
  • 英语_阅读_water protection team_待读