3419. Minimize the Maximum Edge Weight of Graph
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# 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 []
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        vector<vector<pair<int, int>>> graph(n);

        for (const auto& edge : edges) {
            if (edge[0] != 0) {
                graph[edge[1]].emplace_back(edge[0], edge[2]);
            }
        }

        unordered_set<int> visited;
        visited.insert(0);
        int result = 0;

        using EdgeTuple = tuple<int, int, int>;
        priority_queue<EdgeTuple, vector<EdgeTuple>, greater<>> pq;

        for (const auto& edge : graph[0]) {
            pq.push({edge.second, 0, edge.first});
        }

        while (visited.size() < n && !pq.empty()) {
            auto [weight, start, end] = pq.top();
            pq.pop();

            if (visited.count(end)) continue;

            visited.insert(end);
            result = max(result, weight);

            for (const auto& nextEdge : graph[end]) {
                if (!visited.count(nextEdge.first)) {
                    pq.push({nextEdge.second, end, nextEdge.first});
                }
            }
        }

        return visited.size() == n ? result : -1;
    }
};

```
['C++']