mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 10:31:29 +08:00
Pyupgrade to Python 3.9 (#4718)
* Pyupgrade to Python 3.9 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
from collections import deque
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional, Union
|
||||
|
||||
"""
|
||||
Finding the shortest path in 0-1-graph in O(E + V) which is faster than dijkstra.
|
||||
0-1-graph is the weighted graph with the weights equal to 0 or 1.
|
||||
Link: https://codeforces.com/blog/entry/22276
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import deque
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -59,7 +59,7 @@ class AdjacencyList:
|
||||
|
||||
self._graph[from_vertex].append(Edge(to_vertex, weight))
|
||||
|
||||
def get_shortest_path(self, start_vertex: int, finish_vertex: int) -> Optional[int]:
|
||||
def get_shortest_path(self, start_vertex: int, finish_vertex: int) -> int | None:
|
||||
"""
|
||||
Return the shortest distance from start_vertex to finish_vertex in 0-1-graph.
|
||||
1 1 1
|
||||
@ -107,7 +107,7 @@ class AdjacencyList:
|
||||
ValueError: No path from start_vertex to finish_vertex.
|
||||
"""
|
||||
queue = deque([start_vertex])
|
||||
distances: list[Union[int, None]] = [None] * self.size
|
||||
distances: list[int | None] = [None] * self.size
|
||||
distances[start_vertex] = 0
|
||||
|
||||
while queue:
|
||||
|
Reference in New Issue
Block a user