Imagine you're a network engineer tasked with finding the most reliable communication path between two servers in an unreliable network. You have an undirected weighted graph of n nodes (0-indexed), where each edge represents a network connection with a specific probability of successful data transmission.
Given:
edges[i] = [a, b]- an undirected edge connecting nodesaandbsuccProb[i]- probability of success for traversing edgei(between 0.0 and 1.0)startandendnodes
Goal: Find the path from start to end with the maximum probability of success and return that probability.
If no path exists, return 0. Your answer will be accepted if it differs from the correct answer by at most 1e-5.
Example: If you have edges [[0,1],[1,2],[0,2]] with probabilities [0.5, 0.5, 0.2], the path 0→1→2 has probability 0.5 × 0.5 = 0.25, while direct path 0→2 has probability 0.2. Choose the higher probability path!
Input & Output
Visualization
Time & Space Complexity
Each edge is processed once, and priority queue operations take O(log V) time
Space for adjacency list, priority queue, and probability tracking array
Constraints
- 2 ≤ n ≤ 104
- 0 ≤ edges.length ≤ 2 × 104
- edges[i].length == 2
- 0 ≤ ai, bi ≤ n - 1
- ai ≠ bi
- 0 ≤ start, end ≤ n - 1
- start ≠ end
- 0 < succProb[i] ≤ 1
- At most one edge between any two nodes