| Conditions | 5 |
| Total Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import heapq |
||
| 5 | def shortestPath(graph, start, end): |
||
| 6 | queue = [(0, start, [])] |
||
| 7 | seen = set() |
||
| 8 | while True: |
||
| 9 | (cost, v, path) = heapq.heappop(queue) |
||
| 10 | if v not in seen: |
||
| 11 | path = path + [v] |
||
| 12 | seen.add(v) |
||
| 13 | if v == end: |
||
| 14 | return cost, path |
||
| 15 | for (next_item, c) in graph[v].items(): |
||
| 16 | heapq.heappush(queue, (cost + c, next_item, path)) |
||
| 17 | return queue |
||
| 18 | |||
| 47 |