mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
55 lines
1.9 KiB
HTML
55 lines
1.9 KiB
HTML
<p>在一个有向图中,节点分别标记为 <code>0, 1, ..., n-1</code>。图中每条边为红色或者蓝色,且存在自环或平行边。</p>
|
||
|
||
<p><code>red_edges</code> 中的每一个 <code>[i, j]</code> 对表示从节点 <code>i</code> 到节点 <code>j</code> 的红色有向边。类似地,<code>blue_edges</code> 中的每一个 <code>[i, j]</code> 对表示从节点 <code>i</code> 到节点 <code>j</code> 的蓝色有向边。</p>
|
||
|
||
<p>返回长度为 <code>n</code> 的数组 <code>answer</code>,其中 <code>answer[X]</code> 是从节点 <code>0</code> 到节点 <code>X</code> 的红色边和蓝色边交替出现的最短路径的长度。如果不存在这样的路径,那么 <code>answer[x] = -1</code>。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 3, red_edges = [[0,1],[1,2]], blue_edges = []
|
||
<strong>输出:</strong>[0,1,-1]
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 3, red_edges = [[0,1]], blue_edges = [[2,1]]
|
||
<strong>输出:</strong>[0,1,-1]
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 3, red_edges = [[1,0]], blue_edges = [[2,1]]
|
||
<strong>输出:</strong>[0,-1,-1]
|
||
</pre>
|
||
|
||
<p><strong>示例 4:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 3, red_edges = [[0,1]], blue_edges = [[1,2]]
|
||
<strong>输出:</strong>[0,1,2]
|
||
</pre>
|
||
|
||
<p><strong>示例 5:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 3, red_edges = [[0,1],[0,2]], blue_edges = [[1,0]]
|
||
<strong>输出:</strong>[0,1,1]
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= n <= 100</code></li>
|
||
<li><code>red_edges.length <= 400</code></li>
|
||
<li><code>blue_edges.length <= 400</code></li>
|
||
<li><code>red_edges[i].length == blue_edges[i].length == 2</code></li>
|
||
<li><code>0 <= red_edges[i][j], blue_edges[i][j] < n</code></li>
|
||
</ul>
|