Prim's Algorithm
I got this solution by reading through some of the posted solutions. I found this approach the most intuitive.The idea here is simply to check if you are able t
I got this solution by reading through some of the posted solutions. I found this approach the most intuitive.

The idea here is simply to check if you are able to reach all nodes from `0`. While traversing take the path with minimum weight. Since, we will take the minimum required path (i.e. minimum edges and weights) during traversing so the threshold checking is not required at all.

# Code
```java []
class Solution {
    public int minMaxWeight(int n, int[][] edges, int threshold) {
        List<List<Pair<Integer, Integer>>> adjList = new ArrayList<>();
        for (int i = 0; i < n; i++)
            adjList.add(new ArrayList<>());

        // store the edges in reverse 
        // as we need to traverse from 0 to other nodes
        for (int[] edge : edges) {
            int u = edge[0], v = edge[1], w = edge[2];
            adjList.get(v).add(new Pair(u, w));
        }

        // min heap
        // arranges nodes in ascending order by edge weight
        PriorityQueue<Pair<Integer, Integer>> pq = new PriorityQueue<>((a, b) -> a.getValue() - b.getValue());

        int maxWeight = 0;
        boolean[] vis = new boolean[n];
        pq.add(new Pair(0, 0));

        // run prims algo
        while (!pq.isEmpty()) {
            int node = pq.peek().getKey(), weight = pq.peek().getValue();
            pq.remove();
            if (vis[node])
                continue;
            vis[node] = true;
            
            // keeping track of the maxWeight on the path
            maxWeight = Math.max(weight, maxWeight);
            for (Pair<Integer, Integer> adj : adjList.get(node)) {
                int adjNode = adj.getKey();
                if (!vis[adjNode])
                    pq.add(adj);
            }
        }

        // check if all nodes are visited
        for (int i = 0; i < n; i++)
            if (!vis[i])
                return -1;

        return maxWeight;
    }
}
```
['Java']