{ } </> O(n) // [ ] *p log &&

TRUNK TRICK

Trunk Trick

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

From number theory to graph theory, from data structures to dynamic programming — this is where I document every "aha!" moment along the journey. Built slowly, written carefully.

// 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];
    if (u == v) return u;
    for (int i = LOG-1; i >= 0; i--)
        if (up[u][i] != up[v][i])
            u = up[u][i], v = up[v][i];
    return up[u][0];
}
π λ

TOPICS

Topics I Write About

Every topic here comes from real problems I've encountered. The visualizations are my way of making abstract ideas concrete.

Max Flow Modeling: Baseball Elimination
Graph Theory · Network Flow

Max Flow Modeling

How do you determine whether a sports team is mathematically eliminated from the playoffs? The answer is a maximum flow network — source nodes representing remaining games, team nodes with carefully chosen capacities, and a sink that reveals the truth.

Planar Graphs and Euler's Formula
Graph Theory · Planarity

Planar Graphs & Kuratowski's Theorem

Which graphs can be drawn on a plane without crossing edges? From Euler's formula $V - E + F = 2$ to the forbidden subgraphs $K_5$ and $K_{3,3}$, planarity theory sits at the intersection of discrete mathematics, topology, and computational geometry.

// Disjoint Set Union
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) {
        if (sz[a] < sz[b]) swap(a, b);
        p[b] = a; sz[a] += sz[b];
    }
}
Data Structures · DSU

Disjoint Set Union & Path Compression

The Union-Find data structure with path compression achieves nearly $O(1)$ amortized time per operation. Deceptively simple — just a few lines of code — yet it's the backbone of Kruskal's MST, dynamic connectivity, and countless competitive programming solutions.