Binary search
Code
# Code
```cpp []
#define pb push_back

class Solution {
public:
    vector<vector<pair<int, int>>>g;

    int chk(int v, int m, vector<bool>&vis){
        vis[v]=1;int cnt=1;
        for(auto p:g[v]){
            if(p.second<=m && !vis[p.first])cnt+=chk(p.first, m, vis);
        }
        return cnt;
    }

    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        g.resize(n);
        for(auto e:edges)g[e[1]].pb({e[0], e[2]});
        int l=0, r=1000001;
        while((r-l) > 1){
            int m=l+((r-l)>>1);
            vector<bool>vis(n, 0);
            if(chk(0, m, vis)==n)r=m;
            else l=m;
        }
        return (r==1000001)?-1:r;
    }
};
```
['Binary Search', 'C++']