|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Dynamic forest with path queries via Link-Cut Trees. More...
#include <tpl_link_cut_tree.H>
Classes | |
| struct | Node |
| Internal node of the Link-Cut Tree (opaque handle). More... | |
Public Member Functions | |
| Gen_Link_Cut_Tree ()=default | |
| Default constructor for an empty Link-Cut Tree. | |
| ~Gen_Link_Cut_Tree () | |
| Destructor. | |
| Gen_Link_Cut_Tree (const Gen_Link_Cut_Tree &)=delete | |
| Deleted copy constructor. | |
| Gen_Link_Cut_Tree & | operator= (const Gen_Link_Cut_Tree &)=delete |
| Deleted copy assignment. | |
| Gen_Link_Cut_Tree (Gen_Link_Cut_Tree &&)=delete | |
| Deleted move constructor. | |
| Gen_Link_Cut_Tree & | operator= (Gen_Link_Cut_Tree &&)=delete |
| Deleted move assignment. | |
| Node * | make_vertex (const T &val=T{}) |
Create an isolated vertex with payload val. | |
| Node * | make_vertex (T &&val) |
| Create an isolated vertex (move semantics). | |
| void | destroy_vertex (Node *x) |
| Destroy an isolated vertex. | |
| size_t | size () const noexcept |
| Total number of vertices currently in the forest. | |
| void | make_root (Node *x) |
Make x the root of its represented tree. | |
| Node * | find_root (Node *x) |
Find the root of the represented tree containing x. | |
| bool | connected (Node *u, Node *v) |
Test whether u and v are in the same represented tree. | |
| void | link (Node *u, Node *v) |
Add an edge between u and v, merging their trees. | |
| void | cut (Node *u, Node *v) |
Remove the represented edge between u and v. | |
| Node * | lca (Node *u, Node *v) |
Lowest common ancestor of u and v. | |
| T | path_query (Node *u, Node *v) |
Aggregate (under Monoid) over all vertex values on the path from u to v. | |
| size_t | path_size (Node *u, Node *v) |
Number of vertices on the path from u to v. | |
| const T & | get_val (Node *x) |
Read the payload value of vertex x. | |
| void | set_val (Node *x, const T &val) |
Update the payload value of vertex x and recompute aggregates. | |
| void | path_apply (Node *u, Node *v, const typename LazyTag::tag_type &tag) |
Apply a lazy tag to every vertex on the path from u to v. | |
| size_t | num_components () const noexcept |
| Number of connected components (trees) in the forest. | |
| size_t | tree_size (Node *x) |
Number of vertices in the tree containing x. | |
| size_t | depth (Node *x) |
Depth of x relative to the current root of its tree. | |
| Node * | parent (Node *x) |
Parent of x in the represented tree under the current rooting. | |
| template<typename Op > | |
| void | for_each_node (Op &&op) const |
Call op(Node *) for every vertex in the forest. | |
| template<typename Op > | |
| void | for_each_on_path (Node *u, Node *v, Op &&op) |
Call op(Node *) for every vertex on the path from u to v, in order from u to v. | |
| Array< Node * > | make_path (std::initializer_list< T > vals) |
| Create a path of vertices from an initializer list of values. | |
| Array< Node * > | make_vertices (std::initializer_list< T > vals) |
| Create isolated vertices from an initializer list of values. | |
| template<typename Container > | |
| void | link_edges (const Container &edges) |
| Link every pair in an edge container. | |
| Tree_Node< T > * | export_to_tree_node (Node *root) |
Export the represented tree rooted at root as a Tree_Node<T>. | |
Static Private Member Functions | |
| static bool | is_root (const Node *x) noexcept |
| static bool | is_left (const Node *x) noexcept |
| static void | push (Node *x) noexcept |
| static void | pull (Node *x) noexcept |
| static void | rotate (Node *x) noexcept |
| static void | splay (Node *x) noexcept |
| static Node * | access (Node *x) noexcept |
| template<typename Op > | |
| static void | inorder_traverse (Node *root, Op &&op) |
Private Attributes | |
| Array< Node * > | nodes |
| size_t | n_components = 0 |
Dynamic forest with path queries via Link-Cut Trees.
| T | Value type stored at each vertex. |
| Monoid | Associative combiner for path aggregation. Must satisfy LCTMonoid. |
| LazyTag | Lazy-tag policy for deferred path updates. Must satisfy LCTLazyTag. |
The Gen_Link_Cut_Tree class allows you to manage a dynamic forest of nodes. It is particularly useful for problems where you need to answer connectivity queries or path aggregation queries (e.g., "what is the bottleneck edge on the
path from A to B?") in a network that is constantly changing (edges being added and removed).
Vertices are created via make_vertex(), returning an opaque Node* handle. The tree assumes ownership of all created nodes and will destroy them upon destruction. Handles remain stable as long as the tree is alive.
Link_Cut_Tree (which defaults to int and no-ops) simply to call link(), cut(), and connected().MaxMonoid or MinMonoid. When adding an edge that forms a cycle, find the max/min weight edge on the cycle using path_query() and cut() it.SumMonoid and AddLazyTag to dynamically add values to paths and query path sums.Gen_Link_Cut_Tree instances are mixed. Definition at line 361 of file tpl_link_cut_tree.H.
|
default |
Default constructor for an empty Link-Cut Tree.
|
inline |
Destructor.
Frees all nodes managed by the LCT.
Definition at line 585 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::nodes, and Aleph::Array< T >::size().
|
delete |
Deleted copy constructor.
|
delete |
Deleted move constructor.
|
inlinestaticprivatenoexcept |
Definition at line 545 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::parent, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::pull(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::splay().
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::cut(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::depth(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::destroy_vertex(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::get_val(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::lca(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::parent(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_apply(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_query(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_size(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::set_val().
Test whether u and v are in the same represented tree.
Internally, it checks if find_root(u) is the same as find_root(v).
| u | Handle to the first vertex. |
| v | Handle to the second vertex. |
true if they are connected (in the same tree), false otherwise. | std::invalid_argument | if u or v is null. |
Definition at line 718 of file tpl_link_cut_tree.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root().
Referenced by Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::connected(), example_connectivity(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::export_to_tree_node(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::export_to_tree_node(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::link(), TEST(), TEST(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::tree_size().
Remove the represented edge between u and v.
Splits the tree containing u and v into two trees by deleting the edge between them. It achieves this by making u the root of the tree, and then accessing v. If v is adjacent to u in the represented tree, u will be the left child of v in the auxiliary tree. Breaking this child connection separates them.
| u | Handle to the first vertex of the edge. |
| v | Handle to the second vertex of the edge. |
| std::domain_error | if the edge (u, v) does not exist. |
| std::invalid_argument | if either handle is null. |
Definition at line 769 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_domain_error_if, ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::left, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::n_components, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::parent, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::pull(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::right.
Referenced by Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::cut(), example_connectivity(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::link(), TEST(), TEST(), and TEST().
|
inline |
Depth of x relative to the current root of its tree.
The depth is the number of edges on the path from the root to x. O(log n) amortised.
Definition at line 932 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_invalid_argument_if, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::left, and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::sz.
Destroy an isolated vertex.
| x | Handle to the isolated vertex to destroy. |
| std::invalid_argument | if x is null. |
| std::domain_error | if x is not isolated or does not belong to this tree. |
Definition at line 639 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_domain_error_if, ah_invalid_argument_if, Aleph::and, Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::left, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::n_components, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::nodes, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::parent, Aleph::Array< T >::remove_last(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::right, and Aleph::Array< T >::size().
Referenced by Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::cut(), and Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::link().
|
inline |
Export the represented tree rooted at root as a Tree_Node<T>.
Materializes the current represented tree containing root into an explicit n-ary tree of Tree_Node<T> nodes. A make_root(root) is performed internally to establish the rooting.
The caller owns the returned tree and must free it with destroy_tree(result).
| root | Vertex to use as root of the exported tree. |
Tree_Node<T> * mirroring the represented tree. | std::invalid_argument | if root is null. |
Definition at line 1061 of file tpl_link_cut_tree.H.
References ah_invalid_argument_if, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::connected(), destroy_tree(), Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::for_each_node(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::parent(), and root().
Find the root of the represented tree containing x.
This exposes the path to x and then traverses down the left children of the auxiliary tree to find the node with the minimum depth in the represented tree, which corresponds to the root. The structure is splayed at the end to maintain amortized time bounds.
| x | Handle to a vertex in the tree. |
x. | std::invalid_argument | if x is null. |
Definition at line 693 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_invalid_argument_if, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::left, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::push(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::splay().
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::connected(), example_rerooting(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::find_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::for_each_on_path(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::lca(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::link(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_apply(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_query(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_size(), and TEST().
|
inline |
Call op(Node *) for every vertex in the forest.
Definition at line 965 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::nodes, and Aleph::Array< T >::size().
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::export_to_tree_node().
|
inline |
Call op(Node *) for every vertex on the path from u to v, in order from u to v.
O(path_length log n) amortised.
Definition at line 977 of file tpl_link_cut_tree.H.
References ah_domain_error_if, ah_invalid_argument_if, Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::parent().
Read the payload value of vertex x.
| x | Handle to the vertex. |
| std::invalid_argument | if x is null. |
Definition at line 856 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_invalid_argument_if, and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::val.
Referenced by example_lca(), example_rerooting(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::export_to_tree_node(), and Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::get_edge_val().
|
inlinestaticprivate |
Definition at line 562 of file tpl_link_cut_tree.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::push(), and root().
|
inlinestaticprivatenoexcept |
Definition at line 409 of file tpl_link_cut_tree.H.
References Aleph::and.
|
inlinestaticprivatenoexcept |
Definition at line 403 of file tpl_link_cut_tree.H.
References Aleph::and, and Aleph::divide_and_conquer_partition_dp().
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::rotate(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::splay().
Lowest common ancestor of u and v.
The LCA is relative to the current rooting of the tree. If the structure has been rerooted via make_root(), the LCA will reflect that new hierarchy. Internally, it exposes the path from the root to u, and then begins exposing the path from the root to v. The point where the v path intersects the u path is the LCA.
| u | Handle to the first vertex. |
| v | Handle to the second vertex. |
u and v. | std::domain_error | if u and v are not connected. |
| std::invalid_argument | if either handle is null. |
Definition at line 796 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_domain_error_if, ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root().
Referenced by example_lca().
Add an edge between u and v, merging their trees.
This operation links the tree containing u to the tree containing v. It does this by first making u the root of its tree (make_root(u)). Then, it simply sets v as the parent of u in the represented forest.
The operation requires that u and v are currently in different trees. If they are already connected, a cycle would be formed, which is not allowed in a valid forest representation.
| u | Handle to the vertex that will become a child. |
| v | Handle to the vertex that will become the parent. |
| std::domain_error | if u and v are already in the same tree. |
| std::invalid_argument | if u == v or either handle is null. |
Definition at line 746 of file tpl_link_cut_tree.H.
References ah_domain_error_if, ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::n_components, and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::parent.
Referenced by example_connectivity(), example_lca(), example_path_aggregates(), example_rerooting(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::link(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::link_edges(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_path(), TEST(), TEST(), and TEST().
Link every pair in an edge container.
Definition at line 1036 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::link().
|
inline |
Create a path of vertices from an initializer list of values.
Returns an Array of handles in order. Each consecutive pair is linked.
Definition at line 1004 of file tpl_link_cut_tree.H.
References Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::link(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_vertex().
Make x the root of its represented tree.
This operation changes the represented tree so that x becomes the new root. It exposes the path to x (bringing x to the root of its auxiliary tree) and flips its rev lazy flag. This reverses the depth order of the path, making x the highest node (the new root). Does not create or destroy any edge. After this call find_root(x) == x.
| x | Handle to the vertex to become the new root. |
| std::invalid_argument | if x is null. |
Definition at line 674 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_invalid_argument_if, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::push(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::rev.
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::cut(), example_lca(), example_rerooting(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::export_to_tree_node(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::for_each_on_path(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::link(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::make_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_apply(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_query(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_size(), and TEST().
Create an isolated vertex with payload val.
The vertex is created as a tree of a single node. The Link-Cut Tree retains ownership of the allocated memory. The returned handle must be used for all subsequent operations involving this vertex.
| val | Initial vertex value (default-constructed if omitted). |
Definition at line 612 of file tpl_link_cut_tree.H.
Referenced by example_connectivity(), example_lca(), example_path_aggregates(), example_rerooting(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::link(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_path(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_vertices(), TEST(), TEST(), TEST(), TEST(), and TEST_F().
Create an isolated vertex (move semantics).
| val | Initial vertex value. |
Definition at line 625 of file tpl_link_cut_tree.H.
References Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::n_components, and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::nodes.
|
inline |
Create isolated vertices from an initializer list of values.
Array of handles (no edges created). Definition at line 1023 of file tpl_link_cut_tree.H.
References Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_vertex().
|
inlinenoexcept |
Number of connected components (trees) in the forest.
Definition at line 908 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::n_components.
|
delete |
Deleted copy assignment.
|
delete |
Deleted move assignment.
Parent of x in the represented tree under the current rooting.
Returns nullptr if x is the root of its tree. O(log n) amortised.
Definition at line 944 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::left, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::push(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::right, and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::splay().
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::export_to_tree_node(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::for_each_on_path().
|
inline |
Apply a lazy tag to every vertex on the path from u to v.
Exposes the path between u and v, then applies the given tag to the root of the auxiliary tree representing this path. The change will be pushed down efficiently (lazily) during subsequent operations.
Available only when LazyTag is not NoLazyTag.
| u | Start vertex of the path. |
| v | End vertex of the path. |
| tag | The lazy tag to apply. |
| std::domain_error | if u and v are not connected. |
| std::invalid_argument | if either handle is null. |
Definition at line 891 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_domain_error_if, ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root().
Aggregate (under Monoid) over all vertex values on the path from u to v.
This method first makes u the root of the tree, and then exposes the path up to v by calling access(v). The path from u to v is perfectly captured in the auxiliary tree rooted at v, so the aggregate value is trivially available in v->agg.
| u | Start vertex of the path. |
| v | End vertex of the path. |
| std::domain_error | if u and v are not connected. |
| std::invalid_argument | if either handle is null. |
Definition at line 824 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::agg, ah_domain_error_if, ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root().
Referenced by example_path_aggregates(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::path_query(), and TEST().
Number of vertices on the path from u to v.
| u | Start vertex of the path. |
| v | End vertex of the path. |
u and v (inclusive). | std::domain_error | if u and v are not connected. |
| std::invalid_argument | if either handle is null. |
Definition at line 841 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_domain_error_if, ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::sz.
Referenced by example_rerooting(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::path_size(), and TEST().
|
inlinestaticprivatenoexcept |
Definition at line 450 of file tpl_link_cut_tree.H.
References Aleph::divide_and_conquer_partition_dp().
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::cut(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::rotate(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::set_val().
|
inlinestaticprivatenoexcept |
Definition at line 416 of file tpl_link_cut_tree.H.
References Aleph::divide_and_conquer_partition_dp().
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::inorder_traverse(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::parent(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::splay().
|
inlinestaticprivatenoexcept |
Definition at line 472 of file tpl_link_cut_tree.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::is_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::left, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::parent, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::pull(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::right.
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::splay().
Update the payload value of vertex x and recompute aggregates.
| x | Handle to the vertex to update. |
| val | The new value to set. |
| std::invalid_argument | if x is null. |
Definition at line 869 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), ah_invalid_argument_if, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::pull(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::val.
Referenced by example_path_aggregates(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::set_edge_val(), and TEST().
|
inlinenoexcept |
Total number of vertices currently in the forest.
Definition at line 661 of file tpl_link_cut_tree.H.
References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::nodes, and Aleph::Array< T >::size().
|
inlinestaticprivatenoexcept |
Definition at line 509 of file tpl_link_cut_tree.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::is_root(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::left, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::Node::parent, Aleph::ArrayStack< T >::push(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::push(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::rotate().
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::access(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::parent().
|
inline |
Number of vertices in the tree containing x.
Definition at line 917 of file tpl_link_cut_tree.H.
References ah_invalid_argument_if, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::connected(), Aleph::count(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::nodes, and Aleph::Array< T >::size().
|
private |
Definition at line 399 of file tpl_link_cut_tree.H.
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::cut(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::destroy_vertex(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::link(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_vertex(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::num_components().
Definition at line 398 of file tpl_link_cut_tree.H.
Referenced by Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::~Gen_Link_Cut_Tree(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::destroy_vertex(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::for_each_node(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::make_vertex(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::size(), and Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::tree_size().