Prims to purify your soul
IntuitionThe question wants us to go from other nodes to 0,
Looking at the examples we can observe 2 things

Other nodes may point to 0, thats the right way to
# Intuition
The question wants us to go from other nodes to 0, 
Looking at the examples we can observe 2 things

1. Other nodes may point to 0, thats the right way to build a path from others to 0.
   
2. 0 may point to other nodes initially but this wont make the other nodes reach 0 so this is a failure case.



What if we reversed all the edges pointing to 0? and Tried finding a way from 0 to other nodes which possibly seems easier to implement, lets try it using 
```
    for v,u,w in edges:
        graph[u].append((v, w))
```

Now we want to discard all the edges with maximum weight, so we will always go from node to node in search of shortest weight edge. PRIMS!

# Complexity
- Time complexity: O(ElogE)

- Space complexity: O(V+E)

# Code
```python3 []
class Solution:
    def minMaxWeight(self, n: int, edges: List[List[int]], threshold: int) -> int:
        graph, hq, visited = defaultdict(list), [], set()

        for v,u,w in edges:
            graph[u].append((v, w))
        
        for (v, w) in graph[0]:
            heapq.heappush(hq, [w,0,v])
        visited.add(0)

        res = 0
        while hq:
            w, u, v = heapq.heappop(hq)
            
            if v in visited: continue
            visited.add(v)
            res = max(res, w)

            for (v2, w2) in graph[v]:
                if v2 not in visited:
                    heapq.heappush(hq, [w2, v, v2])
                    
        
        return res if len(visited) == n else -1
                


```
['Hash Table', 'Graph', 'Heap (Priority Queue)', 'Minimum Spanning Tree', 'Python3']