Conversation
Satorien
reviewed
Jan 28, 2026
| https://neetcode.io/problems/count-connected-components/question | ||
| で代用 | ||
| ## step1 | ||
| - 絵が嘘つきすぎてて問題文読み間違えているのか何回も確認する羽目になった |
There was a problem hiding this comment.
自分は図のどこがおかしいのかよく分からないんですが、参考までにお聞きしても良いですか?
| while connected_component: | ||
| connected_node = connected_component.pop() | ||
| for node in edge_dict[connected_node]: | ||
| if node not in unvisited: |
| connected_component_count += 1 | ||
| connected_component = [node] | ||
|
|
||
| while connected_component: |
There was a problem hiding this comment.
connected_componentよりはunvisited_nodes_in_connected_componentという意味合いな気がしますね
unvisited_connected_nodesとかもありかもしれないです
| node1, node2 = edge | ||
| uf.union(node1, node2) | ||
|
|
||
| root_nodes = set() |
| class Solution: | ||
| def countComponents(self, n: int, edges: list[list[int]]) -> int: | ||
| unvisited_vertices = set(range(n)) | ||
| vertex_to_neghbers = collections.defaultdict(set) |
| vertex_to_neghbers = collections.defaultdict(set) | ||
| for vertex1, vertex2 in edges: | ||
| vertex_to_neghbers[vertex1].add(vertex2) | ||
| vertex_to_neghbers[vertex2].add(vertex1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
今回の問題
323. Number of Connected Components in an Undirected Graph
NEET CODE:
323. Number of Connected Components in an Undirected Graph
次に取り組む予定の問題
127. Word Ladder