C++ Solution || Easy to understand || Binary Search
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

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

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
    bool check(int n, int mid, vector<vector<pair<int, int>>> adj, int th)
    {
        vector<int> cnt(n, 0);

        queue<int> q;
        q.push(0);
        cnt[0] = 1;
        int m = 1;

        while(!q.empty())
        {
            int curr = q.front(); q.pop();

            for(auto [next, w] : adj[curr])
            {
                if(w <= mid && !cnt[next])
                {
                    q.push(next);
                    m += ++cnt[next];
                }
            }
        }
        return m == n;
    }
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int th) {
        int  l = 1, r = 1000001;
        vector<vector<pair<int, int>>> adj(n, vector<pair<int, int>>{});

        for(auto v : edges)
            adj[v[1]].push_back({v[0], v[2]});

        while(l < r)
        {
            int mid = (r - l)/ 2 + l;
            if(check(n, mid, adj, th))
                r = mid;
            else
                l = mid + 1;
        }
        return r == 1000001 ? -1 : r;
    }
};
```
['Binary Search', 'Breadth-First Search', 'C++']