28 explicit best_first(std::unordered_map<T, std::vector<std::pair<T, double>>> v = {},
29 std::unordered_map<T, double> nodes = {}) {
31 if ((!v.empty() && nodes.empty()) || (v.empty() && !nodes.empty())) {
32 throw std::logic_error(
"You have to provide two non-empty maps");
34 if (!v.empty() && !nodes.empty()) {
38 }
catch (std::logic_error& e) {
39 std::cerr << e.what() <<
'\n';
97 std::unordered_map<T, bool> visited;
98 std::priority_queue<std::pair<T, double>, std::vector<std::pair<T, double>>,
99 std::greater<std::pair<T, double>>>
101 q.push({start, nodes[start]});
102 visited[start] =
true;
104 int64_t size = q.size();
105 for (int64_t i = 0; i < size; i++) {
106 std::pair<T, double> current = q.top();
107 if (current.first == end) {
111 for (std::pair<T, double>& x : adj[current.first]) {
112 if (visited.find(x.first) == visited.end() &&
113 x.second <= nodes[current.first]) {
114 visited[x.first] =
true;
115 q.push({x.first, nodes[x.first]});