3651 · Number of Connected Components in an Undirected Graph#19
Open
tarinaihitori wants to merge 1 commit into
Open
3651 · Number of Connected Components in an Undirected Graph#19tarinaihitori wants to merge 1 commit into
tarinaihitori wants to merge 1 commit into
Conversation
oda
reviewed
Nov 18, 2024
Comment on lines
85
to
86
There was a problem hiding this comment.
stack = [node_index]でも。
stack という名前、気に入らない人もいるかもしれませんが、私は比較的許容で、というのも「node_index から visit_connected_nodes します。そのために、まず、積む場所を用意して、node_index をいれます。」と言われたら、connected_nodes が積まれるのだろうな、と文脈から「積む」の意味が推測できるからです。
そうでない人がいたらコメントを書くか変数名をもう少し説明的にするかですね。
oda
reviewed
Nov 18, 2024
There was a problem hiding this comment.
visited_node_indexes は visit_connected_nodes 定義より前で宣言してもいいでしょう。adjacency_list も。visit_connected_nodes で使うので。
There was a problem hiding this comment.
今回の問題設定においては、node_indexってすなわちnodeなのでは?とおもいました
確かにランダムアクセスのindexとしても使っているのですが、node_indexと表現しなくてもそれは自明かなと思いました
Comment on lines
182
to
184
There was a problem hiding this comment.
一応
UnionFind内にcomponent_countみたいなメンバを持っておいて、rootが異なるnodeに対してunionが呼ばれたとき減算していくと、各edgeに対してunionした後すぐcomponent countを引き出せます
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.
この問題がLeetCode Premiumの問題だったため、類題を解いた。
類題のURL
https://www.lintcode.com/problem/3651/description
元の問題のURL(プレミアム)
https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/description/