45#include <lal/graphs/tree.hpp>
46#include <lal/graphs/rooted_tree.hpp>
47#include <lal/detail/graphs/traversal.hpp>
48#include <lal/detail/array.hpp>
67 std::enable_if_t< std::is_base_of_v<graphs::tree, tree_t>,
bool> =
true
71 const auto ccsize = t.get_num_nodes_component(x);
72 if (ccsize == 1) {
return 0; }
73 if (ccsize == 2) {
return 1; }
74 if (ccsize == 3) {
return 2; }
77 const uint64_t n = t.get_num_nodes();
85 bfs.set_process_neighbour
86 ( [&](
const auto&,
node,
node v,
bool) { farthest_from_x = v; } );
90 uint64_t diameter = 0;
96 bfs.set_process_neighbour(
97 [&](
const auto&,
node u,
node v,
bool) {
98 distance[v] = distance[u] + 1; diameter = std::max(diameter, distance[v]); }
100 bfs.start_at(farthest_from_x);
Abstract graph Breadth-First Search traversal.
Definition traversal.hpp:89
uint64_t tree_diameter(const tree_t &t, const node x) noexcept
Calculate the diameter of a tree.
Definition tree_diameter.hpp:69
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59