网络延迟时间

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;

}

};

相关推荐
中微极客28 分钟前
多智能体编排实战:CrewAI vs AutoGen(2026版)
大数据·网络·人工智能
Jerry30 分钟前
LeetCode 92. 反转链表 II
算法
小王C语言31 分钟前
【3. 基于 Vibe Coding 的 OJ 平台】. 构建仓库、环境准备、需求梳理、安装依赖
网络·c++
骊城英雄41 分钟前
Rust从入门到精通-trait
人工智能·算法·rust
新手unity自用笔记1 小时前
unity网络基础_1
网络·unity·游戏引擎
可编程芯片开发1 小时前
基于PI控制算法的pwm直流电机控制系统Simulink建模与仿真
算法
小王C语言1 小时前
【8.进行接口测试】:通过 curl 进行接口自动化测试 / 通过 python 程序进行接口自动化测试
网络·c++
一条大祥脚1 小时前
26杭电暑期第三场 DP|费用流|分解质因子|数论|贪心|图论|期望|无穷级数
网络·图论·网络流·无穷级数·费用流
怕浪猫2 小时前
2840亿参数只卖白菜价:DeepSeek V4 Flash 正式版上线,Agent 能力暴涨6倍
人工智能·算法
让学习成为一种生活方式2 小时前
苄基异喹啉生物碱糖基转移酶UGT74AN1晶体--Journal of Agricultural and Food Chemistry
人工智能·算法