Skip to content

Commit 1798c11

Browse files
committed
add is_connected
1 parent 40375ef commit 1798c11

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cpp/graph_util.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,13 @@ std::vector<std::vector<int>> connected_components(const Graph<Cost>& graph) {
7373
}
7474
}
7575
return groups;
76-
}
76+
}
77+
78+
/**
79+
* @brief 無向グラフについて、連結グラフかどうかを判定する。
80+
* @return bool 連結グラフならtrue、連結グラフでないならfalseを返す。
81+
*/
82+
template <typename Cost = int>
83+
bool is_connected(const Graph<Cost>& graph) {
84+
return connected_components(graph).size() == 1;
85+
}

0 commit comments

Comments
 (0)