Clear java solution easy to understand
Intuition
Use binary search with dfs.
Approach
First invert the edges for ease of dfs traversal.
Use binary search to check if the answer satisfied the given co
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
* Use binary search with dfs.

# Approach
<!-- Describe your approach to solving the problem. -->
* First invert the edges for ease of dfs traversal.
* Use binary search to check if the answer satisfied the given conditions are not, if satisfies then try lower values else try higher values.
* Conditions are simple, just check if we can traverse all nodes from 0th node using dfs graph traversal.

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

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

# Code
```java []
class Solution {
    public void dfs(Map<Integer,List<Pair<Integer,Integer>>> graph, boolean[] visited, int i,int maxi) {
        List<Pair<Integer,Integer>> nodes = graph.get(i);
        visited[i] = true;
        if (nodes == null) return;
        for(Pair<Integer,Integer> node : nodes) {
            if (!visited[node.getKey()] && node.getValue() <= maxi) {
                dfs(graph, visited, node.getKey(), maxi);
            }
        }
    }

    public boolean isValid(int n, Map<Integer,List<Pair<Integer,Integer>>> graph, int maxi) {
        boolean[] visited = new boolean[n];
        dfs(graph, visited, 0, maxi);
        for(int i =0;i<n;i++) {
            if (!visited[i]) return false;
        }
        return true;
    }

    public int binarySearch(int n, Map<Integer,List<Pair<Integer,Integer>>> graph) {
        int l = 1, r = 10000000, mid;
        while(l<=r) {
            mid = (l+r)/2;
            if (isValid(n, graph, mid)) r = mid - 1;
            else l = mid + 1;
        }
        return l;
    }
    public int minMaxWeight(int n, int[][] edges, int threshold) {
        Map<Integer,List<Pair<Integer,Integer>>> graph = new HashMap<>();
        for(int i=0;i<edges.length;i++) {
            if (!graph.containsKey(edges[i][1])) {
                graph.put(edges[i][1], new ArrayList<>());
            }
            graph.get(edges[i][1]).add(new Pair<Integer,Integer>(edges[i][0],edges[i][2]));
        }
        int ans = binarySearch(n,graph);
        return  ans == 10000001 ? -1 : ans;
    }
}
```
['Java']