From c3d8751042d0eb6c00f05629848f3f6dc2034327 Mon Sep 17 00:00:00 2001 From: TheVroum <36685559+TheVroum@users.noreply.github.com> Date: Wed, 2 Oct 2024 00:47:37 +0200 Subject: [PATCH] qs --- dijkstra.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dijkstra.py b/dijkstra.py index 0bd1237..4db4009 100644 --- a/dijkstra.py +++ b/dijkstra.py @@ -4,7 +4,6 @@ from collections import defaultdict from functools import cache from typing import Callable - from input import E, V @@ -20,6 +19,7 @@ type FonctionDeLongueur = Callable[[Arc], Réel] type Tas = list[tuple[Réel, Arc]] + @cache def arcs_sortants_map(g: GraphType) -> dict[Sommet, set[Arc]]: retour: defaultdict[Sommet, set[Arc]] = defaultdict(set) @@ -27,6 +27,7 @@ def arcs_sortants_map(g: GraphType) -> dict[Sommet, set[Arc]]: retour[arc[0]].add(arc) return retour + def arcs_sortants(g: GraphType, u: Sommet) -> set[Arc]: return arcs_sortants_map(tuple(frozenset(g_component) for g_component in g))[u] @@ -50,7 +51,6 @@ def plus_courts_chemins( prédécesseurs[s] = None distance[s] = 0 explore(s) - while frontière: e: Arc = heapq.heappop(frontière)[1]; v: Sommet = e[1] if v not in parcouru: @@ -61,4 +61,3 @@ def plus_courts_chemins( pprint(plus_courts_chemins((V, E), lambda x: 1.0, "A")) - -- GitLab