|
14 | 14 | from collections import deque |
15 | 15 |
|
16 | 16 |
|
17 | | -def expand_search(graph: dict[int, list[int]], queue: deque[int], parents: dict[int, int | None], opposite_direction_parents: dict[int, int | None]) -> int | None: |
| 17 | +def expand_search( |
| 18 | + graph: dict[int, list[int]], |
| 19 | + queue: deque[int], |
| 20 | + parents: dict[int, int | None], |
| 21 | + opposite_direction_parents: dict[int, int | None], |
| 22 | +) -> int | None: |
18 | 23 | if not queue: |
19 | 24 | return None |
20 | 25 |
|
@@ -98,13 +103,23 @@ def bidirectional_search( |
98 | 103 | # Continue until both queues are empty or an intersection is found |
99 | 104 | while forward_queue and backward_queue and intersection is None: |
100 | 105 | # Expand forward search |
101 | | - intersection = expand_search(graph=graph, queue=forward_queue, parents=forward_parents, opposite_direction_parents=backward_parents) |
| 106 | + intersection = expand_search( |
| 107 | + graph=graph, |
| 108 | + queue=forward_queue, |
| 109 | + parents=forward_parents, |
| 110 | + opposite_direction_parents=backward_parents, |
| 111 | + ) |
102 | 112 |
|
103 | 113 | # If no intersection found, expand backward search |
104 | 114 | if intersection is not None: |
105 | 115 | break |
106 | 116 |
|
107 | | - intersection = expand_search(graph=graph, queue=backward_queue, parents=backward_parents, opposite_direction_parents=forward_parents) |
| 117 | + intersection = expand_search( |
| 118 | + graph=graph, |
| 119 | + queue=backward_queue, |
| 120 | + parents=backward_parents, |
| 121 | + opposite_direction_parents=forward_parents, |
| 122 | + ) |
108 | 123 |
|
109 | 124 | # If no intersection found, there's no path |
110 | 125 | if intersection is None: |
|
0 commit comments