Skip to content

Conversation

@kazukiii
Copy link
Owner

問題へのリンク
https://www.lintcode.com/problem/3651/

次に解く問題
127. Word Ladder

README.mdへ頭の中の言語化と記録をしています。

public:
int countComponents(int n, vector<vector<int>>& edges) {
vector<vector<int>> adjacency_list(n);
vector<bool> visited(n, false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false は書かなくても zero initialization だったか自信ありますか。

vector は色々と特殊なので、どこかで調べるといいかもしれません。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちら調べてみました。
vectorの場合、false を指定しなくても zero initialization になるんですね。
また、vector<bool> に関しては実装依存ではあるが、各要素がsingle bitに対応付けられるような特殊なメモリ最適化が行われる場合が多いと理解しました。
以下を参考にしました)
https://en.cppreference.com/w/cpp/container/vector
https://en.cppreference.com/w/cpp/container/vector_bool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants