|
| 1 | +<p>You are given an undirected weighted graph of <code>n</code> nodes (0-indexed), represented by an edge list where <code>edges[i] = [a, b]</code> is an undirected edge connecting the nodes <code>a</code> and <code>b</code> with a probability of success of traversing that edge <code>succProb[i]</code>.</p> |
| 2 | + |
| 3 | +<p>Given two nodes <code>start</code> and <code>end</code>, find the path with the maximum probability of success to go from <code>start</code> to <code>end</code> and return its success probability.</p> |
| 4 | + |
| 5 | +<p>If there is no path from <code>start</code> to <code>end</code>, <strong>return 0</strong>. Your answer will be accepted if it differs from the correct answer by at most <strong>1e-5</strong>.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/09/20/1558_ex1.png" style="width: 187px; height: 186px;" /></strong></p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2 |
| 14 | +<strong>Output:</strong> 0.25000 |
| 15 | +<strong>Explanation:</strong> There are two paths from start to end, one having a probability of success = 0.2 and the other has 0.5 * 0.5 = 0.25. |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | + |
| 20 | +<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/09/20/1558_ex2.png" style="width: 189px; height: 186px;" /></strong></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2 |
| 24 | +<strong>Output:</strong> 0.30000 |
| 25 | +</pre> |
| 26 | + |
| 27 | +<p><strong class="example">Example 3:</strong></p> |
| 28 | + |
| 29 | +<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/09/20/1558_ex3.png" style="width: 215px; height: 191px;" /></strong></p> |
| 30 | + |
| 31 | +<pre> |
| 32 | +<strong>Input:</strong> n = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2 |
| 33 | +<strong>Output:</strong> 0.00000 |
| 34 | +<strong>Explanation:</strong> There is no path between 0 and 2. |
| 35 | +</pre> |
| 36 | + |
| 37 | +<p> </p> |
| 38 | +<p><strong>Constraints:</strong></p> |
| 39 | + |
| 40 | +<ul> |
| 41 | + <li><code>2 <= n <= 10^4</code></li> |
| 42 | + <li><code>0 <= start, end < n</code></li> |
| 43 | + <li><code>start != end</code></li> |
| 44 | + <li><code>0 <= a, b < n</code></li> |
| 45 | + <li><code>a != b</code></li> |
| 46 | + <li><code>0 <= succProb.length == edges.length <= 2*10^4</code></li> |
| 47 | + <li><code>0 <= succProb[i] <= 1</code></li> |
| 48 | + <li>There is at most one edge between every two nodes.</li> |
| 49 | +</ul> |
0 commit comments