Heavy-Light Decomposition Template for Tree Path Queries
The following C++ implementation demonstrates a complete Heavy-Light Decomposition (HLD) framework integrated with a lazy propagation segment tree to support efficient path updates and queries on trees. It passes the standard template problem on Luogu.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int MOD;
struct ...
Posted on Mon, 18 May 2026 00:02:42 +0000 by swizzer
Degree Sequences and Constructing Graphs from Graphic Sequences
Definition of Degree
The degree of a vertex (v) in a graph (G), denoted by (d_G(v)), is the number of edges of (G) incident with (v), with each loop counting as two edges. (J.A. Bondy, Graph Theory)
Two fundamental results follow from this definition:
Handshaking Theorem: For any graph (G),
[
\sum_{v \in V} d(v) = 2m
]
where (m) is the number ...
Posted on Fri, 15 May 2026 05:38:38 +0000 by btubalinal
Algorithmic Pattern Extraction and Language-Specific Optimization Techniques
Sorting and Monotonicity
When a problem does not enforce a specific elemant order, applying a sort operation often introduces monotonicity. This property simplifies constraint checking and enables efficient querying through prefix sums combined with binary search.
Processing Cumulative Constraints
By sorting the input array and computing its pr ...
Posted on Tue, 12 May 2026 20:30:23 +0000 by koolaid
Implementing Prim's Algorithm for Minimum Spanning Trees with Road Construction Problem Solution
Prim's Algorithm for Minimum Spanning Trees
Prim's algorithm utilizes a distance array where dist[j] represents the shortest distance from node j to the current connected component. The process begins by selecting an arbitrary starting node and initializing distances to all other nodes.
Algorithm Steps:
Initialize all distances to infinity exc ...
Posted on Sat, 09 May 2026 19:21:43 +0000 by paulieo10