mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
40 lines
1.5 KiB
HTML
40 lines
1.5 KiB
HTML
|
<p>给你一个有 <code>n</code> 个节点的 <strong>有向无环图(DAG)</strong>,请你找出所有从节点 <code>0</code> 到节点 <code>n-1</code> 的路径并输出(<strong>不要求按特定顺序</strong>)</p>
|
|||
|
|
|||
|
<p><meta charset="UTF-8" /> <code>graph[i]</code> 是一个从节点 <code>i</code> 可以访问的所有节点的列表(即从节点 <code>i</code> 到节点 <code>graph[i][j]</code>存在一条有向边)。</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
|
|||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/09/28/all_1.jpg" /></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>graph = [[1,2],[3],[3],[]]
|
|||
|
<strong>输出:</strong>[[0,1,3],[0,2,3]]
|
|||
|
<strong>解释:</strong>有两条路径 0 -> 1 -> 3 和 0 -> 2 -> 3
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
|
|||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/09/28/all_2.jpg" /></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>graph = [[4,3,1],[3,2,4],[3],[4],[]]
|
|||
|
<strong>输出:</strong>[[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>n == graph.length</code></li>
|
|||
|
<li><code>2 <= n <= 15</code></li>
|
|||
|
<li><code>0 <= graph[i][j] < n</code></li>
|
|||
|
<li><code>graph[i][j] != i</code>(即不存在自环)</li>
|
|||
|
<li><code>graph[i]</code> 中的所有元素 <strong>互不相同</strong></li>
|
|||
|
<li>保证输入为 <strong>有向无环图(DAG)</strong></li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<p> </p>
|