File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -57,15 +57,15 @@ def undirected_connected_components(gr):
5757
5858def DFS (gr , s ):
5959 """ Depth first search wrapper """
60- path = []
60+ path = set ([])
6161 depth_first_search (gr , s , path )
6262 return path
6363
6464def depth_first_search (gr , s , path ):
6565 """ Depth first search
6666 Returns a list of nodes "findable" from s """
6767 if s in path : return False
68- path .append (s )
68+ path .add (s )
6969 for each in gr .neighbors (s ):
7070 if each not in path :
7171 depth_first_search (gr , each , path )
@@ -144,7 +144,8 @@ def shortest_path(digr, s):
144144 from s using Dijkstra's algorithm in O(mlogn) time. Uses heaps
145145 for super fast implementation """
146146 nodes_explored = set ([s ])
147- nodes_unexplored = DFS (digr , s )[1 :] # all accessible nodes from s
147+ nodes_unexplored = DFS (digr , s ) # all accessible nodes from s
148+ nodes_unexplored .remove (s )
148149 dist = {s :0 }
149150 node_heap = []
150151
You can’t perform that action at this time.
0 commit comments