mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
49 lines
2.3 KiB
HTML
49 lines
2.3 KiB
HTML
<p>给你一个由 <code>n</code> 个节点(下标从 0 开始)组成的无向加权图,该图由一个描述边的列表组成,其中 <code>edges[i] = [a, b]</code> 表示连接节点 a 和 b 的一条无向边,且该边遍历成功的概率为 <code>succProb[i]</code> 。</p>
|
||
|
||
<p>指定两个节点分别作为起点 <code>start</code> 和终点 <code>end</code> ,请你找出从起点到终点成功概率最大的路径,并返回其成功概率。</p>
|
||
|
||
<p>如果不存在从 <code>start</code> 到 <code>end</code> 的路径,请 <strong>返回 0</strong> 。只要答案与标准答案的误差不超过 <strong>1e-5 </strong>,就会被视作正确答案。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/07/12/1558_ex1.png" style="height: 186px; width: 187px;"></strong></p>
|
||
|
||
<pre><strong>输入:</strong>n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2
|
||
<strong>输出:</strong>0.25000
|
||
<strong>解释:</strong>从起点到终点有两条路径,其中一条的成功概率为 0.2 ,而另一条为 0.5 * 0.5 = 0.25
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/07/12/1558_ex2.png" style="height: 186px; width: 189px;"></strong></p>
|
||
|
||
<pre><strong>输入:</strong>n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2
|
||
<strong>输出:</strong>0.30000
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/07/12/1558_ex3.png" style="height: 191px; width: 215px;"></strong></p>
|
||
|
||
<pre><strong>输入:</strong>n = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2
|
||
<strong>输出:</strong>0.00000
|
||
<strong>解释:</strong>节点 0 和 节点 2 之间不存在路径
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>2 <= n <= 10^4</code></li>
|
||
<li><code>0 <= start, end < n</code></li>
|
||
<li><code>start != end</code></li>
|
||
<li><code>0 <= a, b < n</code></li>
|
||
<li><code>a != b</code></li>
|
||
<li><code>0 <= succProb.length == edges.length <= 2*10^4</code></li>
|
||
<li><code>0 <= succProb[i] <= 1</code></li>
|
||
<li>每两个节点之间最多有一条边</li>
|
||
</ul>
|