✅C++ |  ✅Use Bellman Ford Algorithm
\nclass Solution {\npublic:\n    \n    // I\'m going to use Bellman Ford Algorithm\n    int networkDelayTime(vector<vector<int>>& times, int n, int k) \n    {\n
```\nclass Solution {\npublic:\n    \n    // I\'m going to use Bellman Ford Algorithm\n    int networkDelayTime(vector<vector<int>>& times, int n, int k) \n    {\n        // just created a dis vector that will store the distance for reaching the node\n        // and assign dis[k]=0 because we will start searching from k \n        vector<int>dis(n+1,INT_MAX);\n        dis[k]=0;\n        \n        \n        // we will update our dis vector upto (n-1) times according to bellman\'s ford algo\n        for(int i=1;i<n;i++)\n        {\n            // just checking for all the nodes that are available in our graph\n            for(int j=0;j<times.size();j++)\n            {\n                // extracting source, destination, weight\n                int u=times[j][0];     // source\n                int v=times[j][1];     // destination\n                int w=times[j][2];     // weight\n                 \n                // if current source is not finite value then we can not pick that path \n                // so just check current source is finite or not\n                // and if we have better path for reaching V from U by using W then we update dis[v]\n                if(dis[u]!=INT_MAX && dis[u]+w<dis[v])\n                {\n                    // if we are having better path available then just update our dis\n                    dis[v]=w+dis[u];\n                }\n            }\n        }\n\t\t \n        // take out the best value to reach n from k\n        int ans=0;\n        for(int i=1;i<=n;i++)\n        {\n            // If any node is not reachable from k return -1\n            if(dis[i]==INT_MAX) \n                return -1;  \n            \n            // else take best path\n            ans=max(ans,dis[i]);\n        }\n        return ans;\n        \n    }\n};\n```
['Graph', 'C', 'C++']