Weekly Contest Solution using Prims Algorithm
IntuitionUse Shortest Path AlgorithmApproachA definitive Prims AlgorithmCode
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Use Shortest Path Algorithm
# Approach
<!-- Describe your approach to solving the problem. -->
A definitive Prims Algorithm
# Code
```java []
class Solution {
    public int minMaxWeight(int n, int[][] edges, int threshold) {
        
        Map<Integer,List<int[]>> graph=new HashMap<>();

        for(int[] e:edges){
            List<int[]> l=graph.getOrDefault(e[1],new ArrayList<>());
            l.add(new int[]{e[0],e[2]});
            graph.put(e[1],l);
        }

        PriorityQueue<int[]> pq=new PriorityQueue<>((a,b)->a[2]-b[2]);

        boolean[] visited=new boolean[n];

        for(int[] node:graph.getOrDefault(0,new ArrayList<>())){
            pq.add(new int[]{0,node[0],node[1]});
        }

        int MAX=-1;
        visited[0]=true;
        while(!pq.isEmpty()){
            int[] top=pq.poll();
            if(visited[top[1]]==false){
                MAX=Math.max(MAX,top[2]);
                visited[top[1]]=true;
                for(int[] nodes:graph.getOrDefault(top[1],new ArrayList<>())){
                    pq.add(new int[]{top[1],nodes[0],nodes[1]});
                }
            }
        }
        for(boolean f:visited){
            if(!f){
                return -1;
            }
        }
        return MAX;
    }
}
```
['Hash Table', 'Depth-First Search', 'Breadth-First Search', 'Heap (Priority Queue)', 'Shortest Path', 'Java']