886. Possible Bipartition Medium
1/**
2 * [886] Possible Bipartition
3 *
4 * We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group.
5 * Given the integer n and the array dislikes where dislikes[i] = [ai, bi] indicates that the person labeled ai does not like the person labeled bi, return true if it is possible to split everyone into two groups in this way.
6 *
7 * Example 1:
8 *
9 * Input: n = 4, dislikes = [[1,2],[1,3],[2,4]]
10 * Output: true
11 * Explanation: group1 [1,4] and group2 [2,3].
12 *
13 * Example 2:
14 *
15 * Input: n = 3, dislikes = [[1,2],[1,3],[2,3]]
16 * Output: false
17 *
18 * Example 3:
19 *
20 * Input: n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]
21 * Output: false
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= n <= 2000
27 * 0 <= dislikes.length <= 10^4
28 * dislikes[i].length == 2
29 * 1 <= dislikes[i][j] <= n
30 * ai < bi
31 * All the pairs of dislikes are unique.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/possible-bipartition/
37// discuss: https://leetcode.com/problems/possible-bipartition/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn possible_bipartition(n: i32, dislikes: Vec<Vec<i32>>) -> bool {
43 false
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_886() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.