2685. Count the Number of Complete Components Medium
1/**
2 * [2685] Count the Number of Complete Components
3 *
4 * You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting vertices ai and bi.
5 * Return the number of complete connected components of the graph.
6 * A connected component is a subgraph of a graph in which there exists a path between any two vertices, and no vertex of the subgraph shares an edge with a vertex outside of the subgraph.
7 * A connected component is said to be complete if there exists an edge between every pair of its vertices.
8 *
9 * <strong class="example">Example 1:
10 * <strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/screenshot-from-2023-04-11-23-31-23.png" style="width: 671px; height: 270px;" />
11 *
12 * Input: n = 6, edges = [[0,1],[0,2],[1,2],[3,4]]
13 * Output: 3
14 * Explanation: From the picture above, one can see that all of the components of this graph are complete.
15 *
16 * <strong class="example">Example 2:
17 * <strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/screenshot-from-2023-04-11-23-32-00.png" style="width: 671px; height: 270px;" />
18 *
19 * Input: n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]]
20 * Output: 1
21 * Explanation: The component containing vertices 0, 1, and 2 is complete since there is an edge between every pair of two vertices. On the other hand, the component containing vertices 3, 4, and 5 is not complete since there is no edge between vertices 4 and 5. Thus, the number of complete components in this graph is 1.
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= n <= 50
27 * 0 <= edges.length <= n * (n - 1) / 2
28 * edges[i].length == 2
29 * 0 <= ai, bi <= n - 1
30 * ai != bi
31 * There are no repeated edges.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/count-the-number-of-complete-components/
37// discuss: https://leetcode.com/problems/count-the-number-of-complete-components/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn count_complete_components(n: i32, edges: Vec<Vec<i32>>) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_2685() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.