网络延迟时间

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;

}

};

相关推荐
Dawn-bit9 分钟前
Linux网络进阶:TCP三次握手和四次挥手与TCP连接状态
linux·服务器·网络·tcp/ip·云计算·智能路由器
TheBestRucy1 小时前
Python 九阳神功:从零筑基到线程飞升
服务器·开发语言·网络·人工智能·python
叩码以求索1 小时前
浅谈:前序遍历反转法求解N叉树的后序遍历
算法
xier_ran1 小时前
【infra之路】GPU 存储层次总结:L1 / L2 / HBM
java·网络·数据库
小网洞2 小时前
免费WPA无线握手包在线分析跑包网站
网络·网络安全·密码学·wps
北风toto2 小时前
中缀、前缀、后缀表达式
算法·软件设计师
听取WA声一片(无恶意)2 小时前
CSP-J/CSP-S 深度优先搜索(DFS)完全讲义
c++·算法·深度优先
码流怪侠3 小时前
2026年8月GitHub热榜深度拆解:Agent Skills席卷开源圈,一个“技能包“收割5万星
算法·程序员·github
hold?fish:palm3 小时前
30 两两交换链表中的节点
数据结构·算法·链表
Nil2083 小时前
leetcode 98验证二叉搜索树
算法·leetcode·职场和发展