C++ Binary search BFS
Intuitionwe are inverting the graphy beacuse it is said the all nodes should be able to reach node 0,so we need to do bfs from all nodes T.C will increase.after
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
we are inverting the graphy beacuse it is said the all nodes should be able to reach node 0,so we need to do bfs from all nodes T.C will increase.
after inverting we will be checking how many nodes can be reached from node 0- this approach will be less complex and T.C will be less.

BS beacuse we need not check for all the value.

# 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 {
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        //binary with invert the edges of graph
        vector<vector<pair<int,int>>> adj(n);
int mine=INT_MAX;
int maxe=INT_MIN;
        for(int i=0;i<edges.size();i++){
            adj[edges[i][1]].push_back({edges[i][0],edges[i][2]});
mine=min(mine,edges[i][2]);
maxe=max(maxe,edges[i][2]);
        }
        int low=mine;
        int high=maxe;
        int ans=maxe;
        while(low<=high){
            int mid=(low+high)/2;
           
            if(fun(mid,adj,n)){
                ans=mid;
                high=mid-1;
            }else{
                low=mid+1;
            }
        }
      //ans can be maxe when actually the ans is maxe or when it does not find any ans.
      //so if ans==maxe check again if we are able to visit all nodes if yes then the ans is maxe or else it is -1 as we cannot visit all nodes.
      //if the ans is other than maxe then no need to check
        if(ans==maxe){
                bool x= fun(ans,adj,n);
                return x==true?maxe:-1;
        }
            return ans;
    }

    bool fun(int mid,vector<vector<pair<int,int>>> &adj,int n){
        queue<int> q;
    
        q.push(0);
        vector<int> vis(n,0);
        int cnt=0;
        vis[0]=1;
        while(!q.empty()){
            auto a=q.front();
            q.pop();
            for(auto x:adj[a]){
                if(vis[x.first]) continue;
                if(x.second>mid) continue;
                vis[x.first]=1;
                q.push(x.first);
            }
        }
        for(int i=0;i<vis.size();i++){
            if(vis[i]==1)
            cnt++;
        }

        return cnt==n?true:false;
    }
};
```
['Binary Search', 'Breadth-First Search', 'C++']