Beats 100% - Binary Search - Invert edges - Python3
IntuitionHere threshold can be ignored as we need only one minimum edge to connect to node 0 directly or indirectly.ApproachThe binary search is performed to ch
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

Here threshold can be ignored as we need only one minimum edge to connect to node 0 directly or indirectly.

# Approach
<!-- Describe your approach to solving the problem. -->

The binary search is performed to check the smallest weight that allows us to reach node 0 from all nodes. 

To check if node 0 is reachable from all nodes, the reverse graph is built where edges are inverted, and then dfs is performed from node 0. 

# Complexity
- Time complexity:
    <!-- Add your time complexity here, e.g. $$O(n)$$ --> 
    If W is maximum weight is graph for binary search it is O(logW)
        To check the reachability dfs is performed. Time complexity is O(V+E)
        Overall Time Complexity:- O(logW*(V+E))

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
        To build the adjacency list space complexity is O(V*E), where V is number of vertices and E is number of edges. 
        Recursive Call stack of DFS:- O(V)
        Overall Space complexity:- O(V\*E)

# Code
```python3 []
from collections import defaultdict, deque

from heapq import *

class Solution:

    def check(self, weight, edges, t, n):
        edges = [edge for edge in edges if edge[2]<=weight]

        # g = defaultdict(list)
        outgoing_edge = defaultdict(int)
        reverse_g = defaultdict(list)
        # print(weight, edges)
        for u, v, w in edges:
            # g[u].append((v,w))
            reverse_g[v].append(u)

        r = set()

        def dfs(n):
            if n in r:
                return
            r.add(n)
            for nb in reverse_g[n]:
                dfs(nb)
        dfs(0)
        if len(r) < n:
            return False
        return True
        
    
    def minMaxWeight(self, n: int, edges: List[List[int]], threshold: int) -> int:
        l = 0
        r = 0
        for _, _, w in edges:
         r = max(r, w)   
        result = -1
        while l <= r:
            mid = (l+r)//2
            # print(mid, self.check(78, edges, threshold, n))
            if self.check(mid, edges, threshold, n):
                result = mid
                r = mid-1
            else:
                l = mid + 1
        return result
        
```
['Python3']