Java | Prim | O(V+E)
Code
# Code
```java []
class Solution {
    public int minMaxWeight(int n, int[][] edges, int threshold) {
        Map<Integer, Integer>[] G = new Map[n];
        for(int i = 0; i < n; ++i)
            G[i] = new HashMap<>();
        for(var e: edges){
            int u = e[0], v = e[1], w = e[2];
            G[v].put(u, Math.min(G[v].getOrDefault(u,Integer.MAX_VALUE),w));
        }
        int res = 0;
        Queue<int[]> pq = new PriorityQueue<>((x,y) -> Integer.compare(x[0], y[0]));
        pq.add(new int[]{0,0});
        Set<Integer> visited = new HashSet<>();
        while(!pq.isEmpty()){
            var e = pq.poll();
            int w = e[0], u = e[1];
            if(visited.contains(u)) continue;
            visited.add(u);
            res = Math.max(res, w);
            for(var v: G[u].keySet()){
                w = G[u].get(v);
                pq.add(new int[]{w, v});
            }
        }
        return visited.size() == n ? res : -1;

    }
}
```
['Java']