Using mst

```java []
class Solution {
 
    public int minMaxWeight(int n, int[][] edges, int threshold) {
           List<List<int[]>> adj = new ArrayList<>();
        int[] visited = new int[n];
        for(int i=0;i<n;i++) adj.add(new ArrayList<>());
        
        for(int[] x:edges){
           adj.get(x[1]).add(new int[]{x[0],x[2]});
        }

       // visited[0] = 1;
        int count = 1;
        int ans=0;
        PriorityQueue<int[]> q = new PriorityQueue<>((a,b)->a[1]-b[1]);
        q.offer(new int[]{0,0});
        while(!q.isEmpty()){
            int[] cur = q.poll();
            if(visited[cur[0]]==1)continue;
            ans=Math.max(ans,cur[1]);
            
            visited[cur[0]]=1;
            for(int[] x:adj.get(cur[0])){
                if(visited[x[0]] == 0){
                    
                    q.offer(x);
                   
                }
            }
        }
        for(int i=0;i<n;i++){
            if(visited[i]==0)return -1;
        }
        return ans;  
    }
}
```
['Java']