  For a family of graphs $\mathcal{F}$, a graph $G$ is $\mathcal{F}$-universal
if $G$ contains every graph in $\mathcal{F}$ as a (not necessarily induced)
subgraph. For the family of all graphs on $n$ vertices and of maximum degree at
most two, $\mathcal{H}(n,2)$, we prove that there exists a constant $C$ such
that for $p \geq C \left( \frac{\log n}{n^2} \right)^{\frac{1}{3}}$, the
binomial random graph $G(n,p)$ is typically $\mathcal{H}(n,2)$-universal. This
bound is optimal up to the constant factor as illustrated in the seminal work
of Johansson, Kahn, and Vu for triangle factors. Our result improves
significantly on the previous best bound of $p \geq C \left(\frac{\log
n}{n}\right)^{\frac{1}{2}}$ due to Kim and Lee. In fact, we prove the stronger
result that for the family of all graphs on $n$ vertices, of maximum degree at
most two and of girth at least $\ell$, $\mathcal{H}^{\ell}(n,2)$, $G(n,p)$ is
typically $\mathcal H^{\ell}(n,2)$-universal when $p \geq C \left(\frac{\log
n}{n^{\ell -1}}\right)^{\frac{1}{\ell}}$. This result is also optimal up to the
constant factor. Our results verify (in a weak form) a classical conjecture of
Kahn and Kalai.
