Beat 100% || Clean Solution || Binary Search
Code

# Code
```python3 []
from collections import defaultdict
from typing import List

class Solution:
    def minMaxWeight(self, n: int, edges: List[List[int]], threshold: int) -> int:
        # Initialize variables
        ans = float('inf')
        max_w = max(w for _, _, w in edges)
        min_w = min(w for _, _, w in edges)
        r_graph = defaultdict(list)

        # Build reverse graph
        for a, b, w in edges:
            r_graph[b].append((a, w))
        
        # DFS to check if all nodes can be visited
        def canVisitAll(mid):
            visit = set()
            stack = [0]
            while stack:
                node = stack.pop()
                if node in visit:
                    continue
                visit.add(node)
                for child, w in r_graph[node]:
                    if child not in visit and mid >= w:
                        stack.append(child)
            return len(visit) == n
        
        # Binary search to find the minimum valid `mid`
        left, right = min_w, max_w
        while left <= right:
            mid = (left + right) // 2
            if canVisitAll(mid):
                ans = min(ans, mid)
                right = mid - 1
            else:
                left = mid + 1

        return ans if ans != float('inf') else -1

```
['Python3']