Binary Search with BFS on weights 
IntuitionThe problem involves finding the minimum maximum weight such that all nodes in the graph are reachable from node 0 while ensuring that no edge with a w
# Intuition
The problem involves finding the minimum maximum weight such that all nodes in the graph are reachable from node `0` while ensuring that no edge with a weight greater than the threshold is used. This can be approached by treating the problem as a **binary search** over possible weights and checking connectivity using **Breadth-First Search (BFS)**.

# Approach
1. **Binary Search on Weights**:
   - The goal is to find the smallest maximum weight (`mid`) such that all nodes are reachable from node `0` using edges with weights ≤ `mid`.
   - Use binary search to iterate over possible weights. The search range is from `0` to the maximum weight in the graph.

2. **Graph Construction**:
   - For each candidate weight (`mid`), construct a graph that includes only edges with weights ≤ `mid`.

3. **Connectivity Check**:
   - Use BFS to check if all nodes are reachable from node `0` in the constructed graph.
   - If all nodes are reachable, update the answer and search for a smaller weight.
   - If not, search for a larger weight.

4. **Result**:
   - The smallest weight that satisfies the connectivity condition is the answer.

# Complexity
- **Time complexity**: $$O(E \log W)$$, where:
  - `E` is the number of edges.
  - `W` is the maximum weight in the graph.
  - Binary search runs in $$O(\log W)$$, and BFS runs in $$O(V + E)$$ for each candidate weight.
- **Space complexity**: $$O(V + E)$$, for storing the graph and BFS queue.

# Code
```cpp
#include <vector>
#include <queue>
#include <algorithm>

#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define mp make_pair
#define INF 1e18

using namespace std;

class Solution {
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        if (n == 1) {
            return 0;
        }

        ll maxWeight = 0;
        for (auto& edge : edges) {
            maxWeight = max(maxWeight, (ll)edge[2]);
        }

        ll low = 0, high = maxWeight, answer = -1;
        while (low <= high) {
            ll mid = (low + high) / 2;

            vvll graph(n);
            for (auto& edge : edges) {
                if (edge[2] <= mid) {
                    graph[edge[1]].pb(edge[0]); 
                }
            }

            vi visited(n, 0);
            queue<int> q;
            q.push(0);
            visited[0] = 1;
            ll count = 1; 

            while (!q.empty()) {
                ll u = q.front();
                q.pop();
                for (auto& v : graph[u]) {
                    if (!visited[v]) {
                        visited[v] = 1;
                        count++;
                        q.push(v);
                    }
                }
            }

            if (count == n) {
                answer = mid;
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }

        return answer;
    }
};
['C++']