网络延迟时间

class Solution {

public:

int networkDelayTime(vector<vector<int>>& times, int n, int k) {

vector<vector<pair<int, int>>> graph(n);

for (auto& t : times) {

int u = t0 - 1, v = t1 - 1;

graphu.emplace_back(v, t2);

}

priority_queue<pair<int, int>, vector<pair<int, int>>,

greater<pair<int, int>>>

pq;

pq.push({0, k-1});

vector<int> dist(n, INT_MAX - 10000);

vector<bool> st(n, false);

distk-1=0;

while (pq.size()) {

auto e = pq.top();

pq.pop();

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

if (stu)

continue;

stu = true;

for (auto& o : graphu) {

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

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

distv = distu + ww;

pq.push({distv, v});

}

}

}

int res = 0;

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

if (disti == INT_MAX - 10000)

return -1;

res = max(res, disti);

}

return res;

}

};

相关推荐
通信小呆呆11 小时前
Vandermonde结构及其快速算法详解
线性代数·算法
云泽80811 小时前
笔试算法 - 链表篇(一):移除、反转、合并、回文判断全解析
数据结构·c++·算法·链表
菜菜的顾清寒11 小时前
HOT力扣100(43)二叉树-翻转二叉树
数据结构·算法·leetcode
通信小呆呆11 小时前
Toeplitz结构及其快速算法详解
算法
YikNjy12 小时前
break和continue
java·开发语言·算法
春日见12 小时前
五分钟入门 强化学习---DQN(Deep Q Net)算法与实现
人工智能·python·深度学习·算法·microsoft·机器学习
ytdbc12 小时前
OSPF综合实验
网络
budingxiaomoli12 小时前
动态规划--斐波那契数列模型
算法·动态规划
IT猿手12 小时前
多目标优化算法:多目标蛇优化算法(Multiple Objective Snake Optimizer,MOSO)(提供MATLAB代码)
开发语言·算法·matlab·动态路径规划·光伏模型参数估计