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)/可能的二分法 [possible-bipartition].html
2022-03-29 12:43:11 +08:00

46 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>给定一组&nbsp;<code>n</code>&nbsp;人(编号为&nbsp;<code>1, 2, ..., n</code>&nbsp;我们想把每个人分进<strong>任意</strong>大小的两组。每个人都可能不喜欢其他人,那么他们不应该属于同一组。</p>
<p>给定整数 <code>n</code>&nbsp;和数组 <code>dislikes</code>&nbsp;,其中&nbsp;<code>dislikes[i] = [a<sub>i</sub>, b<sub>i</sub>]</code>&nbsp;,表示不允许将编号为 <code>a<sub>i</sub></code>&nbsp;&nbsp;&nbsp;<code>b<sub>i</sub></code>的人归入同一组。当可以用这种方法将所有人分进两组时,返回 <code>true</code>;否则返回 <code>false</code></p>
<p>&nbsp;</p>
<ol>
</ol>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 4, dislikes = [[1,2],[1,3],[2,4]]
<strong>输出:</strong>true
<strong>解释:</strong>group1 [1,4], group2 [2,3]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 3, dislikes = [[1,2],[1,3],[2,3]]
<strong>输出:</strong>false
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]
<strong>输出:</strong>false
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 2000</code></li>
<li><code>0 &lt;= dislikes.length &lt;= 10<sup>4</sup></code></li>
<li><code>dislikes[i].length == 2</code></li>
<li><code>1 &lt;= dislikes[i][j] &lt;= n</code></li>
<li><code>a<sub>i</sub>&nbsp;&lt; b<sub>i</sub></code></li>
<li><code>dislikes</code>&nbsp;中每一组都 <strong>不同</strong></li>
</ul>
<p>&nbsp;</p>