网络延迟时间

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;

}

};

相关推荐
白帽攻防录4 小时前
SRC 挖洞:Roundcube 预认证 SQL 注入深度复盘,CVE-2026-48842 preg_replace 转义绕过怎么打穿邮件系统
网络·数据库·sql·网络安全·sql注入
海上小飞龙5 小时前
【KMP算法-下篇】同一道题:Java 库函数 2600 微秒,手写 KMP 16 微秒
java·开发语言·算法
青少儿编程课堂5 小时前
后缀自动机解析:本质不同子串与最长重复片段统计
c++·python·算法·bfs·信息学竞赛
朝朝辞暮i5 小时前
C++ 第 12 课:局部变量、作用域、变量生命周期
开发语言·c++·算法
乐迪信息6 小时前
港口船舶逆行怎么管?AI防爆摄像机搭载智能检测算法
大数据·人工智能·深度学习·算法·计算机视觉
Sirens.7 小时前
Java并发锁详解:六类锁策略与 synchronized 底层原理
java·前端·算法
要吃这碗饭8 小时前
深入理解 TCP 协议:从三次握手到可靠传输
网络·网络协议·tcp/ip
和裕8 小时前
全纸结构重型纸箱能否满足 1 吨以上设备出口熏蒸豁免要求?通关合规性全解析
大数据·运维·网络·人工智能·算法
tangguofeng8 小时前
不带头结点的链队操作集(不含InitFlag)(C语言版)
算法
呉師傅9 小时前
得力P2500、M2500系列打印机硒鼓加粉及清零方法【纯享版】
运维·网络·windows·电脑