From 0ffc20496d5b06c66c398c6d584a44030a40fdee Mon Sep 17 00:00:00 2001 From: stefiosif Date: Wed, 14 Sep 2022 19:41:08 +0300 Subject: [PATCH] Add vertices without arcs into the BFTree --- algorithm/breadth_first_search.h | 1 + test/algorithm_test.cc | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/algorithm/breadth_first_search.h b/algorithm/breadth_first_search.h index 84168d1..3be0167 100644 --- a/algorithm/breadth_first_search.h +++ b/algorithm/breadth_first_search.h @@ -46,6 +46,7 @@ std::map> BreadthFirstSearch::execute(const T& root) { if (!visited[u]) { visited[u] = true; tree[v].insert(u); + tree[u]; Q.push(u); } } diff --git a/test/algorithm_test.cc b/test/algorithm_test.cc index d15911c..8b13889 100644 --- a/test/algorithm_test.cc +++ b/test/algorithm_test.cc @@ -114,12 +114,15 @@ TEST_SUITE("Algorithm") { {2, {3, 6}}, {3, {4}}, {4, {5}}, + {5, {}}, {6, {7, 9}}, {7, {8}}, + {8, {}}, {9, {10}}, {10, {11}}, {11, {12}}, - {12, {13}} + {12, {13}}, + {13, {}} }; CHECK_EQ(tree, expected);