|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Story-driven demo of Centroid Decomposition dynamic nearest-center queries. More...
#include <Tree_Decomposition.H>#include <tpl_graph.H>#include <algorithm>#include <array>#include <cassert>#include <format>#include <iostream>#include <limits>Go to the source code of this file.
Functions | |
| int | main () |
| Demonstrates centroid-decomposition-based dynamic nearest-center queries on a fixed tree. | |
Story-driven demo of Centroid Decomposition dynamic nearest-center queries.
Villages form a tree road network. We repeatedly:
Centroid decomposition answers each operation in O(log n).
All per-node arrays are indexed by centroid/HLD integer IDs obtained via cd.id_of(node), not by insertion order, so the example is correct for any graph backend and insertion sequence.
Definition in file centroid_decomposition_example.cc.
| int main | ( | ) |
Demonstrates centroid-decomposition-based dynamic nearest-center queries on a fixed tree.
Builds a small tree of labeled "villages", constructs a Centroid_Decomposition and a Heavy_Light_Decomposition (used as an oracle for exact distances), and exercises:
The program prints diagnostic information (centroid root and ancestor chain), activates sample villages, compares centroid-query results against the brute-force oracle with assertions, and reports success when all checks pass.
Definition at line 76 of file centroid_decomposition_example.cc.
References Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_root_id(), Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Centroid_Decomposition< GT, SA >::for_each_centroid_ancestor_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::id_of(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), k, and Aleph::Gen_Centroid_Decomposition< GT, SA >::size().