Competitive Programming Template Collection

Tarjan's Algorithm for Strongly Connnected Components namespace TarjanSCC { int dfn[N], low[N], index, colorCount; int comp[N], size[N], value[N]; bool inStack[N]; stack<int> stk; vector<int> graph[N]; void tarjan(int u) { dfn[u] = low[u] = ++index; stk.push(u); inStack[u] = true; ...

Posted on Tue, 02 Jun 2026 18:01:50 +0000 by justgrafx

Optimizing Sequence Merging with Dynamic Programming and Matrix Exponentiation Techniques

Problem Overview The problem involves merging a sequence of stones where each stone has a weight. The goal is to merge consecutive stones within a sequence into a single stone with a weight equal to the sum of the merged stones, at a cost equal to that sum. The merging must result in a final number of stones between a given range [L, R], and th ...

Posted on Wed, 13 May 2026 02:50:15 +0000 by vaanil