Binary search + bfs
IntuitionApproach
reverse the map, threshold is useless
use bfs to search the min max problem
Complexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
1. reverse the map, threshold is useless
2. use bfs to search the min max problem
# 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:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        vector<vector<pair<int,int>>> graph(n);
        int l = INT_MAX;
        int r = INT_MIN;
        for(auto & edge : edges){
            graph[edge[1]].push_back({edge[0],edge[2]});
            l = min(l, edge[2]);
            r = max(r, edge[2]);
        }
        while(l < r){
            int m = l + (r-l)/2;
            if(bfs(graph, m, n)) // m is good
                r = m;
            else // m is not enough
                l = m+1;
        }
        if(bfs(graph,r,n))
            return r;
        return -1;

    }

    bool bfs(vector<vector<pair<int,int>>> &graph, int k, int n){
        int ans = 0;
        vector<bool> visited(n, false);
        queue<int> que;
        que.push(0);
        ans++;
        visited[0] = true;
        while(!que.empty()){
            int curr = que.front();
            que.pop();
            for(auto & edge : graph[curr]){
                if(!visited[edge.first]){
                    if(edge.second <=k){
                        que.push(edge.first);
                        ans++;
                        visited[edge.first] = true;
                    }       
                }
            }
        }
        return ans == n;
    }
};
```
['C++']