diff --git a/graph/lowest_common_ancestor.cpp b/graph/lowest_common_ancestor.cpp
index 7d5ab42b49..8c1801a74c 100644
--- a/graph/lowest_common_ancestor.cpp
+++ b/graph/lowest_common_ancestor.cpp
@@ -1,258 +1,327 @@
/**
+ * @file
+ * @brief Centroid Decomposition of a tree
*
- * \file
+ * @details
+ * Centroid Decomposition is a technique for efficiently solving
+ * path queries on trees. A centroid of a tree is a node whose
+ * removal results in no remaining subtree having more than n/2 nodes.
*
- * \brief Data structure for finding the lowest common ancestor
- * of two vertices in a rooted tree using binary lifting.
+ * The decomposition works recursively:
+ * 1. Find the centroid of the current tree
+ * 2. Remove it and recurse on each subtree
+ * This creates a "centroid tree" of depth O(log N)
*
- * \details
- * Algorithm: https://cp-algorithms.com/graph/lca_binary_lifting.html
+ * This implementation demonstrates centroid decomposition by
+ * counting the number of paths of a given length in a tree.
+ *
+ * Algorithm reference: https://cp-algorithms.com/graph/centroid_decomposition.html
*
* Complexity:
- * - Precomputation: \f$O(N \log N)\f$ where \f$N\f$ is the number of vertices
- * in the tree
+ * - Preprocessing: \f$O(N \log N)\f$
* - Query: \f$O(\log N)\f$
- * - Space: \f$O(N \log N)\f$
+ * - Space: \f$O(N)\f$
*
- * Example:
- *
Tree:
+ * Example tree:
*
- * _ 3 _
- * / | \
- * 1 6 4
- * / | / \ \
- * 7 5 2 8 0
- * |
- * 9
+ * 1
+ * / | \
+ * 2 3 4
+ * / \
+ * 5 6
*
*
- *
lowest_common_ancestor(7, 4) = 3
- *
lowest_common_ancestor(9, 6) = 6
- *
lowest_common_ancestor(0, 0) = 0
- *
lowest_common_ancestor(8, 2) = 6
- *
- * The query is symmetrical, therefore
- * lowest_common_ancestor(x, y) = lowest_common_ancestor(y, x)
+ * @author Your Name
*/
-
+
#include
-#include
-#include
-#include
+#include
+#include