单源最短路径

#include<iostream>

#include<vector>

#include<queue>

#include <climits>

using namespace std;

const int N=1e5+10;

long long distN;

typedef pair<int,int> PII;

vector<PII>graphN;

priority_queue<PII,vector<PII>,greater<PII>>pq;

int n,m,s;

void dijkstra(){

for(int i=0;i<=n;++i)disti=INT_MAX;

vector<bool>st(n,false);

dists=0;

pq.push({0,s});

while(pq.size()){

auto e=pq.top();pq.pop();

int w=e.first,u=e.second;

if(stu)continue;

stu=true;

for(auto &p:graphu){

int ww=p.second,v=p.first;

if(!stv&&distv>distu+ww){

distv=distu+ww;

pq.push({distv,v});

}

}

}

}

int main(){

cin>>n>>m>>s;

for(int i=0;i<m;++i){

int u,v,w;cin>>u>>v>>w;

graphu.push_back({v,w});

}

dijkstra();

for(int i=1;i<=n;++i)cout<<disti<<" ";

return 0;

}

相关推荐
I_belong_to_jesus17 小时前
C++关于分支预测的优化1
开发语言·c++·算法
Rabitebla18 小时前
【Linux】进程控制(十二) 自定义 Shell(二):内建命令与进程工作目录管理
linux·c++·笔记·学习·bash
码客-ygluu1 天前
一个通用游戏数据服务器
c++·架构
another heaven1 天前
【C/C++ Ranges 是零开销抽象吗?拆开管道、惰性求值和编译期膨胀】
c语言·开发语言·c++
Code_Solitude1 天前
C语言动态内存 + 柔性数组 + 数组名退化
c语言·算法·柔性数组
上海潭龙东海科技有限公司1 天前
客运站管控之动态孪生技术方案(新增一屏管控模块
数据仓库·人工智能·算法·重构·动态规划
YLCHUP1 天前
【思维&图论建模】题解:债权(debt)_图论_建模_思路转化_思维题目_C++算法竞赛
c++·笔记·算法·数学建模·贪心算法·深度优先·图论
xiaoye-duck1 天前
《C++ 项目:手写大模型接入 SDK》会话模块整合:内存 SessionManager 与 DataManager 持久化联动
开发语言·数据库·c++·语言模型
思麟呀1 天前
背包DP(01背包+完全背包)
c++·算法