diff --git a/graphs/minimum_spanning_tree_boruvka.py b/graphs/minimum_spanning_tree_boruvka.py index 8ef8f6b7c827..fcbb4a7ff366 100644 --- a/graphs/minimum_spanning_tree_boruvka.py +++ b/graphs/minimum_spanning_tree_boruvka.py @@ -167,9 +167,9 @@ def boruvka_mst(graph) -> "Graph": union_find = Graph.UnionFind() mst_edges = [] while num_components > 1: - cheap_edge = {} - for vertex in graph.get_vertices(): - cheap_edge[vertex] = -1 + cheap_edge: dict[int, list[int] | None] = dict.fromkeys( + graph.get_vertices() + ) edges = graph.get_edges() for edge in edges: @@ -180,13 +180,12 @@ def boruvka_mst(graph) -> "Graph": set1 = union_find.find(head) set2 = union_find.find(tail) if set1 != set2: - if cheap_edge[set1] == -1 or cheap_edge[set1][2] > weight: - cheap_edge[set1] = [head, tail, weight] - - if cheap_edge[set2] == -1 or cheap_edge[set2][2] > weight: - cheap_edge[set2] = [head, tail, weight] + for component in (set1, set2): + current = cheap_edge[component] + if current is None or current[2] > weight: + cheap_edge[component] = [head, tail, weight] for head_tail_weight in cheap_edge.values(): - if head_tail_weight != -1: + if head_tail_weight is not None: head, tail, weight = head_tail_weight if union_find.find(head) != union_find.find(tail): union_find.union(head, tail) diff --git a/pyproject.toml b/pyproject.toml index 52bd60b9d3aa..03c5d234303f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -321,7 +321,6 @@ rules.deprecated = "ignore" rules.invalid-argument-type = "ignore" rules.invalid-return-type = "ignore" rules.no-matching-overload = "ignore" -rules.not-iterable = "ignore" rules.not-subscriptable = "ignore" rules.parameter-already-assigned = "ignore" rules.unresolved-attribute = "ignore"