Easy understanding JAVA solution 100% beats solution 
Complexity
Time complexity:  O(nlog(n))

Space complexity: O(n)
Code
![image.png](https://assets.leetcode.com/users/images/af56de2d-c6dd-4550-8175-aa7771f26410_1736692900.4017942.png)

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

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

# Code
```java []
class Solution {
    public boolean possible(int w, int[][] edges, int n){
        List<List<Integer>> adj = new ArrayList<>();
        int[] visited = new int[n];
        for(int i=0;i<n;i++) adj.add(new ArrayList<>());
        
        for(int[] x:edges){
            if(x[2] <= w){
                adj.get(x[1]).add(x[0]);
            }
        }

        visited[0] = 1;
        int count = 1;
        Queue<Integer> q = new LinkedList<>();
        q.offer(0);
        while(!q.isEmpty()){
            int cur = q.poll();
            for(int x:adj.get(cur)){
                if(visited[x] == 0){
                    visited[x] = 1;
                    q.offer(x);
                    count+=1;
                }
            }
        }
        return count == n;
    }
    public int minMaxWeight(int n, int[][] edges, int threshold) {
        int min = Integer.MAX_VALUE;
        int max = 0;
        for(int[] x:edges){
            min = Math.min(min,x[2]);
            max = Math.max(max,x[2]);
        }
        int ans = -1;

        while(min <= max){
            int mid = (min+max)/2;
            if(possible(mid,edges,n)){
                ans = mid;
                max = mid-1;
            }else{
                min = mid+1;
            }
        }
        return ans;
    }
}
```
['Java']