Python | Prim's Algorithm | O(V+E)
Code
# Code
```python3 []
from heapq import heappush, heappop
class Solution:
    def minMaxWeight(self, n: int, edges: List[List[int]], threshold: int) -> int:
        G = defaultdict(list)
        for u,v,w in edges:
            G[v].append((u,w))
        heap = [(0,0)]
        visited = set()
        res = 0
        while heap:
            w,u = heappop(heap)
            if u in visited: continue
            visited.add(u)
            res = max(res, w)
            for (v,w) in G[u]:
                heappush(heap, (w,v))
        return res if len(visited) == n else -1


        
        
        
```
['Python3']