网络延迟时间

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;

}

};

相关推荐
Eyfcom8 小时前
〖物流数据安全 02〗差分隐私与同态加密的工程边界:跨境物流快递系统该为隐私付出多少计算代价?
算法·机器学习·同态加密·跨境物流快递系统·物流数据安全
郝学胜-神的一滴9 小时前
Effective STL 条款15:注意字符串实现上的差异
java·开发语言·数据结构·c++·算法·visualstudio
wuyk5559 小时前
AI 时代的嵌入式该怎么学-09-嵌入式vs后端vs算法
人工智能·stm32·单片机·嵌入式硬件·mcu·物联网·算法
labuladong11 小时前
全新的算法 & Agent 课程页上线
算法·llm·agent
leobertlan12 小时前
好玩系列 | 以简构繁,从把玩一把天平进入信息论和编码
算法
电科_银尘12 小时前
【大模型算法与工程 48】项目实战:可调用、可追踪的大模型问答服务
算法
电科_银尘13 小时前
【大模型算法与工程 47】服务工程:并发、排队、限流与可观测性
算法