C++ BFS, beats > 90%
IntuitionConsider what the solution will look like: All of the nodes must be able to reach node 0, but otherwise we can remove as many edges as we want. So it b
# Intuition
Consider what the solution will look like: All of the nodes must be able to reach node 0, but otherwise we can remove as many edges as we want. So it becomes a tree, with node 0 as the root and each edge [a,b] denoting a child-parent relationship. Thinking it this way, the threshold becomes irrelevant because each node only has one parent.

# Approach
Three steps:

1. First convert edges to a structure that can be traversed more easily - a vector of child nodes for each node. We can ignore all outgoing edges from 0.

2. Use BFS starting from node 0. Keep track of maximum weight in path to root node. For each child node, check if the current maximum is larger than max of the parent + weight of the edge from child to parent. If so, update the maximum (i.e. minimize it).

3. Lastly, go through all nodes to get min-max for all nodes. If any node was not updated during step 2, it means the graph was disconnected return -1, otherwise the answer is the max.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    vector<vector<int>> childEdges;
    vector<int> maxWeight;

    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        childEdges.resize(n);
        maxWeight.resize(n, INT_MAX);
        maxWeight[0] = 0;

        // Step 1
        for (int i = 0; i < edges.size(); ++i) {
            if (edges[i][0] != 0) {
                childEdges[edges[i][1]].push_back(i);
            }
        }

        // Step 2
        unordered_set<int> nodes = {0};

        while (!nodes.empty()) {
            unordered_set<int> nextNodes;

            for (int node : nodes) {
                for (int edgeIndex : childEdges[node]) {
                    int child = edges[edgeIndex][0];
                    int weight = edges[edgeIndex][2];

                    if (maxWeight[child] > max(maxWeight[node], weight)) {
                        maxWeight[child] = max(maxWeight[node], weight);
                        nextNodes.insert(child);
                    }
                }
            }

            nodes = std::move(nextNodes);
        }

        // Step 3
        int ans = 0;
        for (int weight : maxWeight) {
            if (weight == INT_MAX)
                return -1;
            ans = max(ans, weight);
        }

        return ans;
    }
};
```
['C++']