Reverse Edges // Beats 97% runtime // cpp // java
IntuitionIf we draw some graphs , we observe that we don't really need threshold value given in the question . As per my observation best possible answer will h
# Intuition
If we draw some graphs , we observe that we don't really need threshold value given in the question . As per my observation best possible answer will have threshold value = 1 .

Now we need minimum possible value of the maximum edge from each node all the way to 0.So one way is we start from each node like 1,2,3,....,n-1 and go all the way to 0 and during each time we can store the max edge wt in res variable.This is actually possible but will give tle as its tc will go around O(N*N*log(N)) ( approx . )

Another way is to basically reverse the edges so our que changes to minimum possible value of the maximum edge starting from 0 to each node.

Below is the code of modified dikstra.Code explanation i will provide in comments.
# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(E*log(N))

- Space complexity:


# Code
```cpp []
class Solution {
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        vector<vector<pair<int,int>>> graph(n);
        for(int i=0 ; i<edges.size() ; i++){
            int u = edges[i][0];
            int v = edges[i][1];
            int wt = edges[i][2];
            graph[v].push_back({u,wt}); // reversing the graph v->u
        }
        vector<int> edge(n, INT_MAX);// it stores the min possible val of the max edge wt from 0 to that node.
        edge[0] = 0;// reaching 0 from 0 cost 0.

        priority_queue<pair<int,int>,vector<pair<int,int>> , greater<pair<int,int>>> pq;
        pq.push({0,0}); //{wt , u}

        while(!pq.empty()){
            auto [wt,u] = pq.top();pq.pop();

            if(edge[u] < wt) continue;// this is optimization step , 
// (5,2) is already in pq , now if further this edge[2] got updated to 3 , so pq will have (3,2) . so if after that this (5,2) appears then we should not do further calulations based on this data as a better data (3,2) is aleady in the pq.

            for(int i=0 ; i<graph[u].size() ; i++){
                int v = graph[u][i].first;
                int w = graph[u][i].second;
// ok , so here let suppose u = 1 and v = 2.So we are going to 2 via 1
// wt is 2 and w is 1 , it means to reach 1 we need min of max edge wt as 2 and to reach 1 to 2 we have edge w as 1 , so if we are considering this edge to actually go to 2 via 1 , we need to put edge[2] = max(1,2).
                if(max(w,wt) < edge[v]){
                    edge[v] = max(w,wt);
                    pq.push({edge[v],v});
                }
            }
        }
        int res = INT_MIN;
        for(int i=0 ; i<n ; i++){
            res = max(res,edge[i]);
        }
        return res == INT_MAX?-1:res;
    }
};
// Hope it helps.
```
['C++']