Javascript - Binary Search
Code
# Code
```javascript []
/**
 * @param {number} n
 * @param {number[][]} edges
 * @param {number} threshold
 * @return {number}
 */
var minMaxWeight = function (n, edges, _) {
  const graph = new Array(n).fill().map(() => []);
  for (const [node1, node2, weight] of edges) {
    graph[node2].push([node1, weight]);
  }

  let low = 0;
  let high = 10 ** 6;
  let ans = Infinity;
  while (low <= high) {
    const mid = Math.floor((low + high) / 2);
    const count = new Array(n).fill(0);
    const isOk = dfs(0, mid, count, graph) === n;
    if (isOk) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }

  return ans === Infinity ? -1 : ans;
};

function dfs(curr, mid, count, graph) {
  count[curr] = 1;
  for (const [next, weight] of graph[curr]) {
    if (weight <= mid && count[next] === 0) {
      count[curr] += dfs(next, mid, count, graph);
    }
  }
  return count[curr];
}

```
['Binary Search', 'JavaScript']