Skip to content

Commit 480e151

Browse files
committed
add is_tree
1 parent 657d420 commit 480e151

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cpp/graph_util.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,12 @@ template <typename Cost = int>
8383
bool is_connected(const Graph<Cost>& graph) {
8484
return connected_components(graph).size() == 1;
8585
}
86+
87+
/**
88+
* @brief 無向グラフについて、木かどうかを判定する。
89+
* @return bool 木ならtrue、木でないならfalseを返す。
90+
*/
91+
template <typename Cost = int>
92+
bool is_tree(const Graph<Cost>& graph) {
93+
return graph.m == graph.n - 1 && is_connected(graph);
94+
}

0 commit comments

Comments
 (0)