# Matching in a Class of Four-Neighbor Grid Forests: A Cubic Bound for Path Components **Historical research record (updated 2026-10-12).** The [standalone proof](cubic-bound.en.md) now establishes the general cubic bound. The derivations, remainders, and counterexamples below retain their historical order. Statements that a problem is unresolved refer to that stage or local method; stronger auxiliary claims do not automatically follow from the general bound. This document gives a self-contained analysis of the [candidate-list implementation](../../std.cpp) when every component of the road forest is a path. The proof was prepared by Codex (GPT-6). See the [main complexity proof](../../complexity.en.md) for general forests. The subsequent [root-to-leaf path proof](complexity-chains.en.md) improves this subclass to $W\le(6n-5)N$ and also covers path queries on branching roads. This document retains the original direction-string border argument and its independent lemma. ## Result and scope Let $F$ be the set of road cells, with $N\le n^2$ cells. If the road forest has maximum degree at most $2$, so that every component is a path or an isolated vertex, then every input walk satisfies $$ \boxed{W\le(16n+1)N,\qquad T=O(n^2+m+nN)\subseteq O(n^3+m),} $$ where $W$ is the total number of candidate checks. The query may extend either end of the visited path and may move repeatedly among previously visited offsets. If a new offset creates a branch, no candidate can pass that round: a road path cannot contain a branch. The disjoint horizontal stripes used for the lower bound in the main complexity proof also belong to this subclass. Consequently, when $m\ge n-1$, its worst-case bounds meet at $\Theta(n^3+m)$. ## A bound on borders of a direction string Encode a grid path with no repeated vertices as a direction string $w$, whose length $L$ is its number of edges. A nonempty string is a **border** of $w$ if it is both a prefix and a suffix. We include the entire string $w$ and write $B(w)$ for the number of borders. **Lemma.** If the path can be translated into an $n\times n$ grid, then $$ B(w)\le4n. $$ The lemma only requires that the path have no repeated vertices; it need not be an induced path. The following proof does not rely on an external string theorem. ### 1. The shortest period and the longest border An integer $p\in[1,L]$ is a period of a string if $w_i=w_{i+p}$ whenever both positions are defined. If $p$ is the shortest period, the longest proper border has length $L-p$. This length is zero if there is no nonempty proper border. All borders can be listed by repeatedly replacing the current string with its longest proper border. Every shorter border is also a border of the longest proper border, and the converse holds. Thus each positive length in this chain represents exactly one nonempty border. ### 2. Prefixes at least twice as long as the period Suppose the shortest period of $w$ is $p$. Any prefix of length $\ell\ge2p$ certainly has period $p$. Suppose it also has a period $q
0$. Therefore, in a stage with $k\ge2$, setting $r=k-1\le n-2$ gives
$$
k-1\le C_n\ln\frac{k+1}{2}
\le C_n\ln\frac L{L'}.
$$
A stage with $k=1$ and a nonempty remainder costs $1$ and at least halves the length. Since $C_n\ge1/\ln2$, it satisfies the same cost bound.
Charge $1$ separately for the final step from a positive length to zero. Summing the logarithms over all other stages gives
$$
B(w)\le C_n\ln L+1.
$$
A path with no repeated vertices uses at most $n^2$ cells, so $L