MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / networkDelayTime

Method networkDelayTime

C++/Network-delay-time.cpp:5–18  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3class Solution {
4public:
5 int networkDelayTime(vector<vector<int>>& times, int N, int K) {
6 vector<long long int> d(N + 1, INT_MAX);
7 d[K] = 0;
8 for (int i = 0; i < N; ++i) {
9 for (int j = 0; j < times.size(); ++j) {
10 if (d[times[j][1]] > d[times[j][0]] + times[j][2]) {
11 d[times[j][1]] = d[times[j][0]] + times[j][2];
12 }
13 }
14 }
15
16 int a = *max_element(d.begin() + 1, d.end());
17 return a >= INT_MAX ? -1 : a;
18 }
19};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected