1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/冗余连接 II [redundant-connection-ii].html
2022-03-29 12:43:11 +08:00

35 lines
1.9 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>在本问题中,有根树指满足以下条件的 <strong>有向</strong> 图。该树只有一个根节点,所有其他节点都是该根节点的后继。该树除了根节点之外的每一个节点都有且只有一个父节点,而根节点没有父节点。</p>
<p>输入一个有向图,该图由一个有着 <code>n</code> 个节点(节点值不重复,从 <code>1</code><code>n</code>)的树及一条附加的有向边构成。附加的边包含在 <code>1</code><code>n</code> 中的两个不同顶点间,这条附加的边不属于树中已存在的边。</p>
<p>结果图是一个以边组成的二维数组 <code>edges</code> 。 每个元素是一对 <code>[u<sub>i</sub>, v<sub>i</sub>]</code>,用以表示 <strong>有向 </strong>图中连接顶点 <code>u<sub>i</sub></code> 和顶点 <code>v<sub>i</sub></code> 的边,其中 <code>u<sub>i</sub></code><code>v<sub>i</sub></code> 的一个父节点。</p>
<p>返回一条能删除的边,使得剩下的图是有 <code>n</code> 个节点的有根树。若有多个答案,返回最后出现在给定二维数组的答案。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/20/graph1.jpg" style="width: 222px; height: 222px;" />
<pre>
<strong>输入:</strong>edges = [[1,2],[1,3],[2,3]]
<strong>输出:</strong>[2,3]
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/20/graph2.jpg" style="width: 222px; height: 382px;" />
<pre>
<strong>输入:</strong>edges = [[1,2],[2,3],[3,4],[4,1],[1,5]]
<strong>输出:</strong>[4,1]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == edges.length</code></li>
<li><code>3 <= n <= 1000</code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>1 <= u<sub>i</sub>, v<sub>i</sub> <= n</code></li>
</ul>