Path With Maximum Probability

Given an undirected graph with success probabilities on edges, return the maximum probability of reaching the destination from the start. Pattern focus: Dijkstra. Use a max-priority queue or an equivalent transformation so higher-probability states are expanded first.

Input Format

n = node count, edges = undirected edges, succProb = edge probabilities, start = source, end = destination

Output Format

maximum success probability from start to end

Constraints

  • 2 <= n <= 10^4
  • 1 <= edges.length <= 2 * 10^4
  • 0 <= succProb[i] <= 1

Examples

Example 1:

Input:

n = 3
edges = [[0,1],[1,2],[0,2]]
succProb = [0.5,0.5,0.2]
start = 0
end = 2

Output:

0.25

Explanation:

The best path is 0 -> 1 -> 2 with probability 0.25.

Example 2:

Input:

n = 3
edges = [[0,1]]
succProb = [0.7]
start = 0
end = 1

Output:

0.7

Explanation:

There is a single direct edge.

Example 3:

Input:

n = 3
edges = [[0,1]]
succProb = [0.7]
start = 0
end = 2

Output:

0.0

Explanation:

The destination is unreachable.

Loading...
Path With Maximum Probability - Shortest Path