Built slowly, written carefully.

cubic-bezier(0.16, 1, 0.30, 1)
Master the trunk, then the tricks.
trunktrick / homelive
TrunkTrick
HomeBlogAlgoLab
GitHub
Personal knowledge base
Trunk Trick

An undergraduate at Xi'an Jiaotong University, an independent developer, and a competitive programmer obsessed with the craft of algorithms.

Read the BlogExplore AlgoLab
lca.cppbinary lifting
// Lowest Common Ancestor
int lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int diff = depth[u] - depth[v];
  for (int i = 0; diff; i++, diff >>= 1)
    if (diff & 1) u = up[u][i];
  return up[u][0];
}
The manifesto04
Master the trunk, then the tricks.

Every complex technique is a tree. The trunk is the core insight; the tricks are the optimizations that make it hold up in practice.

POSTS
LAB NOTES
TOOLS
GRAPH THEORY · NETWORK FLOW01

Max Flow Modeling

Baseball elimination, decided by capacities.

GRAPH THEORY · PLANARITY02

Planar Graphs

Kuratowski's theorem, drawn in the plane.

DATA STRUCTURES · DSU03

Disjoint Set Union

Nearly O(1) amortized, in a few lines.

// path compression int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); } void unite(int a, int b) { a = find(a), b = find(b); if (a != b) { p[b] = a; sz[a] += sz[b]; } }
CONTIGUITAS
Physical memory contiguity
ISCA '23xv6implementation
potential contiguity
■ movable   ■ unmovable
01ConfinementUnmovable pages live at one end.
02Dynamic resizingThe boundary follows memory pressure.
03Hardware migrationSrc to Dst, no software loop.
He plays against your historyKick Start 2021 · Round C
Rock · Paper · Scissors
EXPECTED SCORE · W=50014,573.5 100.0%
R
33%
P
33%
S
33%
four strings of sixty characters — once written, the day is decided.
Blog
Thoughts on algorithms, contests, and the craft of code.
ListOrbit
Nov
Oct
Aug
Jun
May
History ProblemNov 17, 2026
33 posts · one ring per monthnewest at the centre
AlgoLab/ contest-algo / workspace3D GRAPH · LIVE
Contest ALGOMachine Learning
NUMBER THEORY 8
Euler Totient Function
Chinese Remainder Theorem
DATA STRUCTURES 12
LCA ? LCA . LCA !
Binary Indexed Tree
GRAPH THEORY 9
Network Maximum Flow
The great Kosaraju
MATH & ANALYSIS 11
The forgotten FFT
CONTESTS 13
History Problem
LCA ? LCA . LCA !CONTIGUITAS×
3D GraphGraphvizExcalidraw

Every complex technique is a tree.

TrunkTrick
My future here
Building motion field