@@ -60,7 +60,10 @@ def bellman_ford(self, start: str) -> dict:
6060
6161 for vertex_a in self .graph :
6262 for vertex_a , vertex_b , weight in self .edges :
63- if distances [vertex_a ] != sys .maxsize - 1 and distances [vertex_a ] + weight < distances [vertex_b ]:
63+ if (
64+ distances [vertex_a ] != sys .maxsize - 1
65+ and distances [vertex_a ] + weight < distances [vertex_b ]
66+ ):
6467 distances [vertex_b ] = distances [vertex_a ] + weight
6568
6669 return distances
@@ -82,13 +85,25 @@ def johnson_algo(self) -> list[dict]:
8285
8386 for i in range (len (self .edges )):
8487 vertex_a , vertex_b , weight = self .edges [i ]
85- self .edges [i ] = (vertex_a , vertex_b , weight + hash_path [vertex_a ] - hash_path [vertex_b ])
88+ self .edges [i ] = (
89+ vertex_a ,
90+ vertex_b ,
91+ weight + hash_path [vertex_a ] - hash_path [vertex_b ],
92+ )
8693
8794 self .graph .pop ("#" )
88- self .edges = [(vertex1 , vertex2 , node_weight ) for vertex1 , vertex2 , node_weight in self .edges if vertex1 != "#" ]
95+ self .edges = [
96+ (vertex1 , vertex2 , node_weight )
97+ for vertex1 , vertex2 , node_weight in self .edges
98+ if vertex1 != "#"
99+ ]
89100
90101 for vertex in self .graph :
91- self .graph [vertex ] = [(vertex2 , node_weight ) for vertex1 , vertex2 , node_weight in self .edges if vertex1 == vertex ]
102+ self .graph [vertex ] = [
103+ (vertex2 , node_weight )
104+ for vertex1 , vertex2 , node_weight in self .edges
105+ if vertex1 == vertex
106+ ]
92107
93108 distances = []
94109 for vertex1 in self .graph :
0 commit comments