Count the Number of Complete Components

Solution Code
for vertex in range(n):
            if not visited[vertex]:
                component = [], queue = [vertex]
                visited[vertex] = True
                while queue:
                    current = queue.pop(0)
                    component.append(current)
                    for neighbor in graph[current]:
                        if not visited[neighbor]:
                            visited[neighbor] = True
                            queue.append(neighbor)
                
                is_complete = True
                for node in component:
                    if len(graph[node]) != len(component) - 1:
                        is_complete = False; break
                if is_complete: complete_components += 1
        return complete_components

Time Complexity

O(N + M)

Space Complexity

O(N + M)