1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/访问所有节点的最短路径 [shortest-path-visiting-all-nodes].html
2022-03-29 12:43:11 +08:00

41 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>存在一个由 <code>n</code> 个节点组成的无向连通图,图中的节点按从 <code>0</code><code>n - 1</code> 编号。</p>
<p>给你一个数组 <code>graph</code> 表示这个图。其中,<code>graph[i]</code> 是一个列表,由所有与节点 <code>i</code> 直接相连的节点组成。</p>
<p>返回能够访问所有节点的最短路径的长度。你可以在任一节点开始和停止,也可以多次重访节点,并且可以重用边。</p>
<p>&nbsp;</p>
<ol>
</ol>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/12/shortest1-graph.jpg" style="width: 222px; height: 183px;" />
<pre>
<strong>输入:</strong>graph = [[1,2,3],[0],[0],[0]]
<strong>输出:</strong>4
<strong>解释:</strong>一种可能的路径为 [1,0,2,0,3]</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/05/12/shortest2-graph.jpg" style="width: 382px; height: 222px;" /></p>
<pre>
<strong>输入:</strong>graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]
<strong>输出:</strong>4
<strong>解释:</strong>一种可能的路径为 [0,1,4,2,3]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == graph.length</code></li>
<li><code>1 &lt;= n &lt;= 12</code></li>
<li><code>0 &lt;= graph[i].length &lt;&nbsp;n</code></li>
<li><code>graph[i]</code> 不包含 <code>i</code></li>
<li>如果 <code>graph[a]</code> 包含 <code>b</code> ,那么 <code>graph[b]</code> 也包含 <code>a</code></li>
<li>输入的图总是连通图</li>
</ul>