[C++] Bellman Ford
C++\n\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n        vector<int> dist(N + 1, INT_MAX);\n        dist[
**C++**\n```\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n        vector<int> dist(N + 1, INT_MAX);\n        dist[K] = 0;\n        for (int i = 0; i < N; i++) {\n            for (vector<int> e : times) {\n                int u = e[0], v = e[1], w = e[2];\n                if (dist[u] != INT_MAX && dist[v] > dist[u] + w) {\n                    dist[v] = dist[u] + w;\n                }\n            }\n        }\n\n        int maxwait = 0;\n        for (int i = 1; i <= N; i++)\n            maxwait = max(maxwait, dist[i]);\n        return maxwait == INT_MAX ? -1 : maxwait;\n    }\n};\n```
[]