50#include <lal/graphs/tree.hpp>
51#include <lal/graphs/rooted_tree.hpp>
52#include <lal/internal/graphs/traversal.hpp>
53#include <lal/internal/data_array.hpp>
61 std::is_base_of_v<graphs::free_tree, T> ||
62 std::is_base_of_v<graphs::rooted_tree, T>,
65uint32_t tree_diameter(
const T& t) {
66 if (t.get_num_nodes_component(0) == 1) {
return 0; }
68 const uint64_t n = t.get_num_nodes();
72 if constexpr (std::is_base_of_v<graphs::rooted_tree, T>) {
73 bfs.set_use_rev_edges(
true);
76 bfs.set_use_rev_edges(
false);
82 bfs.set_process_neighbour
83 ( [&](
const auto&,
node,
node v,
bool) { farthest_from_0 = v; } );
87 uint32_t diameter = 0;
88 data_array<uint32_t> distance(n, 0);
91 if constexpr (std::is_base_of_v<graphs::rooted_tree, T>) {
92 bfs.set_use_rev_edges(
true);
95 bfs.set_use_rev_edges(
false);
98 bfs.set_process_neighbour(
99 [&](
const auto&,
node u,
node v,
bool) {
100 distance[v] = distance[u] + 1; diameter = std::max(diameter, distance[v]); }
102 bfs.start_at(farthest_from_0);
Main namespace of the library.
Definition definitions.hpp:48
uint32_t node
Node type.
Definition definitions.hpp:51