Binary Search on Answer|| C++ ||
IntuitionConsider mid value as the maximum edge weight you can have in your graph. If predicate(mid) == true then pred(mid+1),predicate(mid+2) and so on will al
# Intuition
Consider mid value as the maximum edge weight you can have in your graph. If predicate(mid) == true then pred(mid+1),predicate(mid+2) and so on will also be true. Hence the solution has monotonic nature. So we can apply binary search here.

# Approach
The only thing we need is to find a predicate function which can return us true or false by checkig the conditions in O(n) time.

First of all we will remove all edges with wt > mid.
Now just make a graph by remaining edges.

Now since we want that all nodes should reach 0, what we can do is reverse the graph. We can try reaching all other nodes from 0.

The condition of threshold value can be ingnored because if there is a path from 0 to that node (whose degree is > threshold) that means there is at least one path through which we can reach that node. Hence other unnecessary edges from that node can be removed.

# Complexity
- Time complexity:
- O(n*log n)

# Code
```cpp []
class Solution {
private:
    void dfs(int node,vector<vector<int>> &gp,vector<int> &vis){
        vis[node] = 1;
        for(auto &nxt : gp[node]){
            if(!vis[nxt]) dfs(nxt,gp,vis);
        }
    }
    bool pred(int n,vector<vector<int>> &edges,int threshold,int max_wt){
        vector<vector<int>> gp(n);
        vector<int> indeg(n,0);
        for(auto &e : edges){
            if(e[2]<=max_wt){
                gp[e[1]].push_back(e[0]);
                indeg[e[0]]++;
            }
        }

        vector<int> vis(n,0);
        dfs(0,gp,vis);

        for(int i = 0; i<n; i++){
            if(vis[i] == 0) return false;
        }

        return true;
    }
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        int low = 1,high = 1000000;
        int ans = -1;

        while(low<=high){
            int mid = (low + high)>>1;
            if(pred(n,edges,threshold,mid)){
                ans = mid;
                high = mid-1;
            }
            else low = mid+1;
            
        }

        return ans;
    }
};
```
['C++']