Easy soltion
IntuitionThink of revering all the edges and do a traversal from node 0 to all the other node and carry the minimum of all the maximum weights of all paths from
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Think of revering all the edges and do a traversal from node 0 to all the other node and carry the minimum of all the maximum weights of all paths from 0 to that node.

# Approach
The code is designed to solve a graph problem where we compute the minimum of all maximum weights for paths from node 0 to every other node in a directed graph. It also determines the maximum of these minimum weights across all nodes, with an additional check against a given threshold.

# 1. Function: minOfMaxWeights
This function computes the minimum of all maximum weights for paths from node 0 to every other node.

Steps:
Initialization:

1. A result vector, ans, is initialized with infinity (INT_MAX) for all nodes, representing that the path weight to each node is initially unknown. The weight for node 0 is set to 0 because the path from node 0 to itself has no weight.
A priority queue (min-heap) is used to process nodes based on the smallest current maximum weight seen so far.
Algorithm:

2. Start with node 0 and push it into the priority queue with a weight of 0.
Process nodes in the priority queue:
Extract the node with the smallest current maximum weight.
If the extracted weight is greater than the already recorded weight for this node, skip further processing of this node.
For each neighbor of the current node, calculate the maximum weight of the path leading to it as the larger of the current maximum weight and the edge weight to that neighbor.
If this new weight is smaller than the previously recorded weight for the neighbor, update it in the result vector and push the neighbor into the queue for further processing.

3. Return:

Once all nodes are processed, the result vector, ans, contains the minimum of all maximum weights for paths from node 0 to each node.
# 2. Function: minMaxWeight
This function computes the overall result by using the minOfMaxWeights function and checks the result against the threshold.

Steps:
1. Convert Edge List to Adjacency List:

2. Convert the list of edges into an adjacency list for efficient graph traversal. Each edge is represented as a pair of the destination node and its weight.
Call minOfMaxWeights:

3. Use the adjacency list to compute the result vector, where each element represents the minimum of all maximum weights for paths from node 0 to the corresponding node.
Compute the Final Result:

4. Find the maximum value from the result vector, representing the largest of the minimum maximum weights across all nodes.
If the result is still infinity (indicating no valid path exists) or is negative infinity (indicating no meaningful computation was made), return -1. Otherwise, return the computed result.


# 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:

vector<int> minOfMaxWeights(int n, vector<pair<int, int>> graph[]) {
    vector<int> ans(n, INT_MAX);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; // Min-heap

    ans[0] = 0;
    pq.push({0, 0});

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

        if (current_max_weight > ans[node]) continue;

        for (auto [neighbor, weight] : graph[node]) {
            int new_max_weight = max(current_max_weight, weight);
            if (new_max_weight < ans[neighbor]) {
                ans[neighbor] = new_max_weight;
                pq.push({new_max_weight, neighbor});
            }
        }
    }

    return ans;
}

    
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        //int n = edges.size();
        vector<pair<int,int>> adj[n];

        for(auto it: edges) {
            adj[it[1]].push_back({it[0], it[2]});
        }

        vector<int> ans(n, INT_MAX);
        ans = minOfMaxWeights(n, adj);
        int result = INT_MIN;
        for(auto it: ans) result = max(result, it);

        return result == INT_MAX || result == INT_MIN? -1 : result;
    }
};
```
['C++']