master
Benjamin Kraft 2 years ago
parent 0fb217fb22
commit 378143f61f
  1. 12
      src/days/12/Day12.cpp
  2. 1
      src/days/12/Day12.h

@ -61,8 +61,8 @@ map<Day12::Vertex, uint64> Day12::dijkstra(Graph &graph, Vertex start) {
queue.erase(u);
for (const Vertex &v : queue){
if (!graph.E.contains({u, v}))
for (const Vertex &v : graph.out[u]){
if (!queue.contains(v))
continue;
size_t newDist = dist[u] + 1;
@ -100,10 +100,14 @@ Day12::Graph Day12::parseGraph(bool reverse) {
auto checkEdges = [&g, readChar, this](Vertex v1, Vertex v2){
char c1 = readChar(input[v1.second][v1.first]);
char c2 = readChar(input[v2.second][v2.first]);
if (c2 <= c1 + 1)
if (c2 <= c1 + 1){
g.E.insert({v1, v2});
if (c1 <= c2 + 1)
g.out[v1].insert(v2);
}
if (c1 <= c2 + 1) {
g.E.insert({v2, v1});
g.out[v2].insert(v1);
}
};
for (Vertex v : g.V){

@ -10,6 +10,7 @@ class Day12 : public Day {
struct Graph {
set<Vertex> V;
set<Edge> E;
map<Vertex, set<Vertex>> out;
};
map<Day12::Vertex, uint64> dijkstra(Graph&,Vertex);

Loading…
Cancel
Save