Finding Shortest Paths in the Reversed Graph
Approach
Reverse the edges and build the adjacency list.
Use BFS starting from node 0, picking the shortest edge at each step.
If all nodes are visited, return
# Approach
- Reverse the edges and build the adjacency list.
- Use BFS starting from node 0, picking the shortest edge at each step.
- If all nodes are visited, return the maximum edge weight encountered; otherwise, return -1.

# Complexity
- Time complexity:
$$O(E*logN)$$ 

- Space complexity:
$$O(E+N)$$
# Code
```python3 []
class Solution:
    def minMaxWeight(self, n: int, edges: List[List[int]], threshold: int) -> int:
        adj = defaultdict(list)
        for [a, b, w] in edges:
            adj[b].append((a, w))

        res = 0
        seen = set()
        pq = [(0, 0)]

        while pq:
            w, node = heappop(pq)
            if node in seen:
                continue
            seen.add(node)
            res = max(res, w)
            for nei, wei in adj[node]:
                heappush(pq, (wei, nei))

        return res if len(seen) == n else -1

```
['Breadth-First Search', 'Heap (Priority Queue)', 'Python3']