Fastest Solution in Cpp. (With proper explanation).
IntuitionThe problem can be solved using binary search and graph traversal techniques. The key idea is to minimize the maximum edge weight while ensuring all no
# Intuition
The problem can be solved using binary search and graph traversal techniques. The key idea is to minimize the maximum edge weight while ensuring all nodes in the graph can reach node 0. To achieve this, we iteratively determine if a candidate maximum edge weight is feasible by verifying reachability using Depth-First Search (DFS) on a reversed graph.

# Approach
->Reversed Graph Construction
->Binary Search on Maximum Edge Weight
->Depth-First Search (DFS)

# Complexity
- Time complexity:
O(E+log(maxWeight)×(V+E))

- Space complexity:
O(V+E)

# Code
```cpp []

#include <bits/stdc++.h>
using namespace std;
class Solution {
public:

/*
    Function: dfs    
        - i (int): The current node being visited.
        - m (int): The maximum allowed edge weight for traversal.
        - ral (vector<vector<pair<int, int>>> &): The reversed adjacency list where ral[j]
          contains pairs of (node, weight) representing edges directed towards node 'j'.
        - vis (vector<int> &): A vector to keep track of visited nodes.    
        - int: The total number of nodes reachable from node 'i' without exceeding weight 'm'.
*/
int dfs(int i, int m, vector<vector<pair<int, int>>> &ral, vector<int> &vis) {
    int res = vis[i] = 1;
    for (auto [j, w] : ral[i])
        if (w <= m && !vis[j])
            res += dfs(j, m, ral, vis);
    return res;
}

/*
    Function: minMaxWeight
    
        - n (int): The number of nodes in the graph, labeled from 0 to n-1.
        - edges (vector<vector<int>>): A list of edges where each edge is represented as
          [Ai, Bi, Wi], indicating a directed edge from node Ai to node Bi with weight Wi.
        - threshold (int): (Note: In this implementation, 'threshold' is not utilized.)

        - int: The minimized maximum edge weight required for all nodes to reach node '0'.
               Returns -1 if such a configuration is not possible.
*/
int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {

    vector<vector<pair<int, int>>> ral(n);
    for (auto &e : edges)
        ral[e[1]].push_back({e[0], e[2]});
    
    
    int l = 1, r = 1000001;
    
    
    while (l < r) {
        int m = (l + r) / 2;
        
        vector<int> vis(n, 0);
        
        if (dfs(0, m, ral, vis) == n)
            r = m;
        else
            l = m + 1;
    }
    
    return l == 1000001 ? -1 : l;
}

};

```
['C++']