C++ solution
SolutionThe goal of this problem is to minimize the maximum edge weight in a directed weighted graph while ensuring that node 0 remains reachable from all other
# Solution
The goal of this problem is to minimize the maximum edge weight in a directed weighted graph while ensuring that node 0 remains reachable from all other nodes and that each node has at most threshold outgoing edges. To achieve this, we may need to remove some edges while maintaining connectivity.

To approach this problem efficiently, we utilize binary search on the maximum edge weight. First, we determine the range of possible maximum edge weights, which spans from the smallest weight in the graph to the largest weight among all edges. We then perform a binary search within this range.

For each candidate weight in our binary search, we attempt to construct a valid graph by removing all edges whose weights exceed the current candidate value. Once we prune the graph in this way, we check whether all nodes can still reach node 0 while respecting the threshold constraint on outgoing edges. If the graph remains valid, it means we might be able to minimize the maximum edge weight further, so we decrease the search range and test with an even smaller weight. However, if the graph becomes disconnected, we must increase the search range to allow for heavier edges.

For example, if we test with a maximum edge weight of 5 and find that it is possible to satisfy all constraints by removing all edges heavier than 5, we then try a lower value, such as 3, to check if we can further reduce the maximum weight. If reducing the threshold further disconnects the graph, we know that 3 is too restrictive, so we must increase the limit to restore connectivity.

By performing this binary search on the maximum edge weight, we efficiently determine the smallest possible value that allows all conditions to be met. This approach ensures that we don’t need to test every possible weight manually, significantly optimizing the solution.

# Trick
Notice that I try to check if a graph is valid using a reverse graph. In this case, the threshold variable is useless, so this is the trick here. Good day.

# Code
```cpp []
using pii = pair<int, int>;

class Solution {
public:
    bool isValid(int n, int maxW, int threshold, vector<vector<int>>& edges) {
        vector<vector<int>> rev(n);
        for (auto& edge : edges) {
            int u = edge[0], v = edge[1], w = edge[2];
            if (w <= maxW) {
                rev[v].push_back(u);
            }
        }
        vector<bool> visited(n, false);
        queue<int> q;
        q.push(0);
        visited[0] = true;
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int v : rev[u]) {
                if (!visited[v]) {
                    visited[v] = true;
                    q.push(v);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (!visited[i]) {
                return false;
            }
        }
        return true;
    }
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        int left = 0, right = 0;
        for (auto& e : edges) {
            right = max(right, e[2]);
        }
        int res = -1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (isValid(n, mid, threshold, edges)) {
                res = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return res;
    }
};
```
['C++']