DFS C++ SOLUTION
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n\nclass Solution {\npublic:\n    void dfs(int node, vector<vector<pair<int, int>>>& graph, vector<int>& dist, int elapsed) {\n        if (elapsed >= dist[node]) return; // If the current time is not better, skip\n        dist[node] = elapsed;\n        for (auto& edge : graph[node]) {\n            int neighbor = edge.first;\n            int time = edge.second;\n            dfs(neighbor, graph, dist, elapsed + time);\n        }\n    }\n\n    int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n        vector<vector<pair<int, int>>> graph(n + 1);\n        for (auto& x : times) {\n            graph[x[0]].push_back({x[1], x[2]});\n        }\n        vector<int> dist(n + 1, INT_MAX);\n        dfs(k, graph, dist, 0); \n\n        int maxDelay = 0;\n        for (int i = 1; i <= n; i++) {\n            if (dist[i] == INT_MAX) return -1; \n            maxDelay = max(maxDelay, dist[i]);\n        }\n        return maxDelay;\n    }\n};\n```
['C++']