|
| 1 | +<h2><a href="https://leetcode.com/problems/count-the-number-of-complete-components">2685. Count the Number of Complete Components</a></h2><h3>Medium</h3><hr><p>You are given an integer <code>n</code>. There is an <strong>undirected</strong> graph with <code>n</code> vertices, numbered from <code>0</code> to <code>n - 1</code>. You are given a 2D integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists an <strong>undirected</strong> edge connecting vertices <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code>.</p> |
| 2 | + |
| 3 | +<p>Return <em>the number of <strong>complete connected components</strong> of the graph</em>.</p> |
| 4 | + |
| 5 | +<p>A <strong>connected component</strong> 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.</p> |
| 6 | + |
| 7 | +<p>A connected component is said to be <b>complete</b> if there exists an edge between every pair of its vertices.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<p><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;" /></strong></p> |
| 13 | + |
| 14 | +<pre> |
| 15 | +<strong>Input:</strong> n = 6, edges = [[0,1],[0,2],[1,2],[3,4]] |
| 16 | +<strong>Output:</strong> 3 |
| 17 | +<strong>Explanation:</strong> From the picture above, one can see that all of the components of this graph are complete. |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | + |
| 22 | +<p><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;" /></strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input:</strong> n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]] |
| 26 | +<strong>Output:</strong> 1 |
| 27 | +<strong>Explanation:</strong> 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. |
| 28 | +</pre> |
| 29 | + |
| 30 | +<p> </p> |
| 31 | +<p><strong>Constraints:</strong></p> |
| 32 | + |
| 33 | +<ul> |
| 34 | + <li><code>1 <= n <= 50</code></li> |
| 35 | + <li><code>0 <= edges.length <= n * (n - 1) / 2</code></li> |
| 36 | + <li><code>edges[i].length == 2</code></li> |
| 37 | + <li><code>0 <= a<sub>i</sub>, b<sub>i</sub> <= n - 1</code></li> |
| 38 | + <li><code>a<sub>i</sub> != b<sub>i</sub></code></li> |
| 39 | + <li>There are no repeated edges.</li> |
| 40 | +</ul> |
0 commit comments