Heavy-Light Decomposition for Tree Operations

Heavy-Light Decomposition (HLD) is a powerful technique that partitions a rooted tree into a set of disjoint paths (chains). This transformation allows for efficient range-based operations (like updates and queries) on tree structures by mapping the nodes into a linear array using a Segment Tree. Core Definitions Heavy Edge: An edge connecting ...

Posted on Sun, 07 Jun 2026 17:42:18 +0000 by asunsha

Querying Path Sums with Value Constraints in Trees Using Persistent Segment Trees

Problem Overview Given a tree with weighted nodes and multiple queries, each query asks for the sum of node weights along the path between two nodes x and y, where the weights fall within a specified range [l, r]. Solution Approach This problem can be efficiently solved using persistent segment trees (also known as chairman trees) combined with ...

Posted on Fri, 15 May 2026 17:00:54 +0000 by bigbob

Tree Coloring Problem Solution Using Fast Fourier Transform

This problem involves calculating valid colorings of a tree under certain constraints. The solution uses inclusion-exclution principle combined with polynomial multiplication via Number Theoretic Transform (NTT). Basic Approach We approach the problem by computing the complement: count arrangements where at least one node violates the coloring ...

Posted on Thu, 14 May 2026 08:51:57 +0000 by Kitara

Tree Root Transition Algorithms for Maximum Subtree Value

Problem A: Tree Value Maximization Approach Define subtree_value[i] as the value generated by the subtree rooted at node i: subtree_value[i] = subtree_size[i] + Σ subtree_value[j] for all children j of i. The initial selection of i as root gives subtree_size[i] value, followed by contributions from its subtrees. Direct computation for each root ...

Posted on Thu, 14 May 2026 08:30:08 +0000 by zeb