C++ BFS w/ Heap/Dijkstra From 0 (Ignore Threshold)
Intuition
Threshold doesn't matter since you only need one outgoing edge for each vertex which is the one that leads to Node 0.
Always pick the edge with the mi
# Intuition
- Threshold doesn't matter since you only need one **outgoing** edge for each vertex which is the one that leads to Node 0.
- Always pick the edge with the minimum weight from the ones already reachable. Initially only 0 can reach 0. You can expand further using BFS with Priority-Queue until all nodes are reachable (if possible).
# Complexity
- Time complexity: $O(E+V*log(V))$ (probably)

- Space complexity: $O(E)$

# Code
```cpp []
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
    int minMaxWeight(int n, vector<vector<int>>& edges, int threshold) {
        vector<map<int, int>> revAdj(n);
        for(auto& edge : edges) {
        	if(edge[0] != 0) {
        		if(revAdj[edge[1]].count(edge[0])) {
        			revAdj[edge[1]][edge[0]] = min(revAdj[edge[1]][edge[0]], edge[2]);
        		}else {
        			revAdj[edge[1]][edge[0]] = edge[2];
        		}
        	}
        }
        set<int> reachable {0};
        int ans = 0;
        // <weight, from, to>
        using ar = array<int, 3>;
        priority_queue<ar, vector<ar>, greater<>> pq;
        for(auto& edge : revAdj[0]) {
        	pq.push({edge.second, 0, edge.first});
        }

        while(int(reachable.size()) < n && !pq.empty()) {
        	auto [w, from, to] = pq.top();
        	pq.pop();
            // already reachable then unnecessary edge to add
        	if(reachable.count(to)) continue;
        	reachable.insert(to);
        	ans = max(ans, w);
        	for(auto& edge : revAdj[to]) {
        		if(!reachable.count(edge.first)) {
        			pq.push({edge.second, to, edge.first});
        		}
        	}
        }
        if(int(reachable.size()) < n) return -1;
        return ans;
    }
};
```
['Breadth-First Search', 'C++']