Reverse Edges | Simple | Medium to Easy | C++
Reverse the Edge DirectionsWe start by reversing all the edge directions in the graph.
This way, instead of finding paths from node 0 to all other nodes, we now

<!-- Describe your first thoughts on how to solve this problem. -->
# Reverse the Edge Directions

We start by reversing all the edge directions in the graph.
This way, instead of finding paths from node 0 to all other nodes, we now need to find paths to node 0 from all other nodes.

**Simplify the Problem**
After reversing, the problem boils down to finding the maximum edge weight on the path leading to node 0 for each node in the graph.
The threshold condition becomes irrelevant because, in this setup, we are effectively reducing the graph so that each node will eventually have at most one outgoing edge.

**Final Answer**
The result is the maximum edge weight among all paths leading to node 0.
If any node cannot reach node 0, it means it's impossible to satisfy the conditions, and we return -1.
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```cpp []
class Solution {
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        int m= edges.size();
        for(int i=0;i<m;i++){
            swap(edges[i][0],edges[i][1]);
        }
        unordered_map<int,vector<pair<int,int>>> adj;
        for(auto it: edges){
            adj[it[0]].push_back({it[1],it[2]});
        }
        vector<int> ans(n,INT_MAX);
        priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
        pq.push({0,0});
        while(!pq.empty()){
            auto t= pq.top();
            pq.pop();
            if(ans[t.second]<=t.first) continue; // Updated line
            ans[t.second]=min(ans[t.second],t.first);
            for(auto it: adj[t.second]){
                if(ans[it.first]>(t.first+it.second)){
                    pq.push({max(t.first,it.second),it.first});
                }
            }
        }
        int maxi= *max_element(ans.begin(),ans.end());
        if(maxi==INT_MAX) return -1;
        else return maxi;
    }
};

```
['C++']