[C++|Java|JavaScrip|Python3] Dijkstra algo
IntuitionThis problem can be solved by Dijkstra's algorithm. We can build a graph of reversed direction. Namely, if there is an edge from u to v in the original
# Intuition
This problem can be solved by Dijkstra's algorithm. We can build a graph of reversed direction. Namely, if there is an edge from `u` to `v` in the original graph. In the reversed graph, the edges is from `v` to `u`. 

Then, we travese the graph from `0` in the reversed graph with a priority queue. By the time when all nodes are traversed, the max weight seen gives the answer. 

# Approach
Here, `threshold` is irrelevant. Imagine that if all nodes can reach `0` in the original graph, then one out-going edge for each node is enough. We can simply assuming that we are giving up the previously seen smaller weight edge while trying the one with larger weights. 

# Complexity
- Time complexity: `O(ElogV)`
- Space complexity: `O(V)`

# Code
```C++ []
class Solution {
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        vector<unordered_map<int, int>> graph(n); 
        for (auto& e : edges) {
            int u = e[0], v = e[1], w = e[2]; 
            if (graph[v].contains(u)) graph[v][u] = min(graph[v][u], w); 
            else graph[v][u] = w; 
        }
        int ans = 0; 
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq; 
        pq.emplace(0, 0); 
        vector<int> dist(n, INT_MAX); 
        dist[0] = 0; 
        unordered_set<int> seen; 
        while (pq.size()) {
            auto [x, v] = pq.top(); pq.pop(); 
            seen.insert(v); 
            if (seen.size() == n) return x; 
            if (dist[v] == x) {
                for (auto& [u, w] : graph[v]) {
                    if (max(x, w) < dist[u]) {
                        pq.emplace(max(x, w), u); 
                        dist[u] = max(x, w); 
                    }
                }
            }
        }
        return -1; 
    }
};
```
```Java []
class Solution {
    public int minMaxWeight(int n, int[][] edges, int threshold) {
        Map<Integer, Integer>[] graph = new Map[n]; 
        for (int i = 0; i < n; ++i)
            graph[i] = new HashMap<>(); 
        for (var e : edges) {
            int u = e[0], v = e[1], w = e[2];
            graph[v].put(u, Math.min(graph[v].getOrDefault(u, Integer.MAX_VALUE), w)); 
        }
        int ans = 0; 
        Queue<int[]> pq = new PriorityQueue<>((x, y) -> Integer.compare(x[0], y[0])); 
        pq.add(new int[]{0, 0}); 
        int[] dist = new int[n]; 
        Arrays.fill(dist, Integer.MAX_VALUE); 
        dist[0] = 0; 
        Set<Integer> seen = new HashSet<>(); 
        while (!pq.isEmpty()) {
            var elem = pq.poll(); 
            int x = elem[0], v = elem[1]; 
            seen.add(v); 
            if (seen.size() == n) return x; 
            if (dist[v] == x) {
                for (var u : graph[v].keySet()) {
                    int w = graph[v].get(u); 
                    if (Math.max(x, w) < dist[u]) {
                        pq.add(new int[]{Math.max(x, w), u}); 
                        dist[u] = Math.max(x, w); 
                    }
                }
            }
        }
        return -1; 
    }
}
```
```JavaScript []
var minMaxWeight = function(n, edges, threshold) {
    const graph = Array(n).fill(0).map(() => new Map()); 
    for (const [u, v, w] of edges) 
        graph[v].set(u, Math.min(graph[v].get(u) ?? Infinity, w)); 
    let ans = 0; 
    const pq = new PriorityQueue({ compare : (x, y) => x[0] - y[0] }); pq.enqueue([0, 0]); 
    const dist = Array(n).fill(Infinity); dist[0] = 0; 
    const seen = new Set(); 
    while (pq.size()) {
        const [x, v] = pq.dequeue(); 
        seen.add(v); 
        if (seen.size == n) return x; 
        if (dist[v] == x) {
            for (const [u, w] of graph[v]) 
                if (Math.max(x, w) < dist[u]) {
                    pq.enqueue([Math.max(x, w), u]); 
                    dist[u] = Math.max(x, w); 
                }
        }
    }
    return -1; 
};
```
```python3 []
class Solution:
    def minMaxWeight(self, n: int, edges: List[List[int]], threshold: int) -> int:
        graph = [defaultdict(lambda : inf) for _ in range(n)]
        for u, v, w in edges: 
            graph[v][u] = min(graph[v][u], w)
        ans = 0 
        pq = [(0, 0)]
        dist = defaultdict(lambda : inf, {0 : 0})
        seen = set()
        while pq: 
            x, v = heappop(pq)
            seen.add(v)
            if len(seen) == n: return x 
            if dist[v] == x: 
                for u, w in graph[v].items(): 
                    if max(x, w) < dist[u]: 
                        heappush(pq, (max(x, w), u))
                        dist[u] = max(x, w)
        return -1 
```
['C++', 'Java', 'Python3', 'JavaScript']