@@ -40,7 +40,7 @@ public int compareTo(PathComponent o) {
40
40
}
41
41
Map <String , PathComponent > pathComponents = new HashMap <>();
42
42
allNodes .forEach (s -> dijkstra (connections , s ).forEach ((k , v ) -> {
43
- var label = k .compareTo (v .a ()) < 0 ? k + " " + v .a () : v .a () + " " + k ;
43
+ var label = k .compareTo (v .node ) < 0 ? k + " " + v .node : v .node + " " + k ;
44
44
pathComponents .computeIfAbsent (label , t -> new PathComponent (t , new AtomicInteger ())).counter .incrementAndGet ();
45
45
}));
46
46
pathComponents .values ().stream ().sorted (reverseOrder ()).limit (3L ).map (PathComponent ::label ).map (s -> s .split (" " )).forEach (s -> {
@@ -51,7 +51,7 @@ public int compareTo(PathComponent o) {
51
51
return reducedSize * (totalSize - reducedSize );
52
52
}
53
53
54
- record ND (String node , int distance ) implements Comparable <ND > {
54
+ public record ND (String node , int distance ) implements Comparable <ND > {
55
55
56
56
@ Override
57
57
public int compareTo (ND o ) {
@@ -66,20 +66,20 @@ public Object part2() {
66
66
return "That's all!" ;
67
67
}
68
68
69
- public Map <String , Pair < T , Integer >> dijkstra (ListMap <T , T > nodes , T node ) {
70
- var queue = new PriorityQueue <Pair < T , Integer > >();
71
- Set <T > visited = new HashSet <>();
72
- Map <T , Pair < T , Integer > > distanceMap = new HashMap <>();
73
- queue .add (new Pair <> (node , 0 ));
69
+ public Map <String , ND > dijkstra (ListMap <String , String > nodes , String node ) {
70
+ var queue = new PriorityQueue <ND >();
71
+ Set <String > visited = new HashSet <>();
72
+ Map <String , ND > distanceMap = new HashMap <>();
73
+ queue .add (new ND (node , 0 ));
74
74
while (!queue .isEmpty ()) {
75
75
var current = queue .remove ();
76
- visited .add (current .a () );
77
- nodes .get (current .a () ).stream ()
76
+ visited .add (current .node );
77
+ nodes .get (current .node ).stream ()
78
78
.filter (s -> !visited .contains (s ))
79
- .filter (s -> !distanceMap .containsKey (s ) || distanceMap .get (s ).b () > current .b () + 1 )
79
+ .filter (s -> !distanceMap .containsKey (s ) || distanceMap .get (s ).distance > current .distance + 1 )
80
80
.forEach (s -> {
81
- distanceMap .put (s , new Pair <> (current .a () , current .b () + 1 ));
82
- queue .add (new Pair <> (s , current .b () + 1 ));
81
+ distanceMap .put (s , new ND (current .node , current .distance + 1 ));
82
+ queue .add (new ND (s , current .distance + 1 ));
83
83
});
84
84
}
85
85
return distanceMap ;
0 commit comments