Java Solution Build Graph Reversely + Binary Search for Edge Weight, Start from 0
IntuitionApproachComplexity
Time complexity:

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

# Approach
<!-- Describe your approach to solving the 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
```java []
class Solution {
    public int minMaxWeight(int n, int[][] edges, int threshold) {
        Map<Integer, List<int[]>> map = new HashMap<>();
        int minedge = Integer.MAX_VALUE;
        int maxedge = Integer.MIN_VALUE;
        for(int[] edge : edges){
            int from = edge[0];
            int to = edge[1];
            int weight = edge[2];
            minedge = Math.min(weight, minedge);
            maxedge = Math.max(weight, maxedge);
            map.putIfAbsent(to, new ArrayList<>());
            map.get(to).add(new int[]{from, weight});
        }
        int left = minedge;
        int right = maxedge;
        int result = Integer.MAX_VALUE;
        while(left <= right){
            int mid = left + (right - left) / 2;
            Set<Integer> visited = new HashSet<>();
            helper(visited, mid, map, 0);
            if(visited.size() == n){
                result = Math.min(result, mid);
                right = mid - 1;
            }
            else{
                left = mid + 1;
            }
        }
        return result == Integer.MAX_VALUE ? -1 : result;
    }
    private void helper(Set<Integer> visited, int maxweight, Map<Integer, List<int[]>> map, int node){
        if(visited.contains(node)){
            return;
        }
        visited.add(node);
        List<int[]> neighbors = map.get(node);
        if(neighbors == null){
            return;
        }
        for(int[] nei : neighbors){
            if(nei[1] > maxweight){
                continue;
            }
            int nextnode = nei[0];
            helper(visited, maxweight, map, nextnode);
        }
    }
}
```
['Java']