https://leetcode.com/problems/path-with-maximum-probability/

Python3

from collections import defaultdict
from heapq import heappush, heappop
from typing import List
 
 
class Solution:
    def maxProbability(self, n: int, edges: List[List[int]], succProb: List[float], start: int, end: int) -> float:
        graph = defaultdict(set)
        for (src, dst), prob in zip(edges, succProb):
            graph[src].add((dst, prob))
            graph[dst].add((src, prob))
 
        max_heap = [(-1, start)]
        seen = set()
 
        while max_heap:
            prob, curr = heappop(max_heap)
            if curr == end:
                return -prob
            seen.add(curr)
            for neigh, n_prob in graph[curr]:
                if neigh not in seen:
                    p = -abs(prob * n_prob)
                    heappush(max_heap, (p, neigh))
        return 0