= Solution
A <locally ringed space> is a <topological space> $X$ equipped with a <sheaf> of commutative <rings> $\mathcal O_X$ whose <stalk> $\mathcal O_{X,x}$ at every point is a <local ring>. A <morphism of locally ringed spaces> $(f,f^\#):(Y,\mathcal O_Y)\to(X,\mathcal O_X)$ consists of a <continuous map> $f:Y\to X$ and a <morphism of sheaves> of <rings> $f^\#: \mathcal O_X\to f_*\mathcal O_Y$, with every induced <stalk> map $\mathcal O_{X,f(y)}\to\mathcal O_{Y,y}$ a <local homomorphism>: the inverse image of the target <maximal ideal> is the source <maximal ideal>. Here $f_*\mathcal O_Y$ is the <direct image sheaf>, with sections $\mathcal O_Y(f^{-1}U)$ on $U$.
Let $\phi:A\to B$ be a <ring homomorphism>. Define the map between the <spectra of rings> by
$$
f(\mathfrak q)=\phi^{-1}(\mathfrak q).
$$
The inverse image is a <prime ideal>, and $f^{-1}(D(a))=D(\phi(a))$. Thus $f$ is a <continuous map>, because the <principal open subsets> form a basis. On these <principal open subsets>, define the <structure sheaf> map using the <localizations>
$$
A_a\longrightarrow B_{\phi(a)},\qquad \frac{b}{a^r}\longmapsto\frac{\phi(b)}{\phi(a)^r}.
$$
These maps commute with restrictions and consequently give a <morphism of sheaves>. At $\mathfrak q$, putting $\mathfrak p=\phi^{-1}\mathfrak q$, the <stalk> map is $A_{\mathfrak p}\to B_{\mathfrak q}$. An element $b/s$ belongs to its inverse image of $\mathfrak qB_{\mathfrak q}$ exactly when $b\in\mathfrak p$, so this is a <local homomorphism>. We have constructed a <morphism of locally ringed spaces>.
Conversely, take a <morphism of locally ringed spaces> $f:\operatorname{Spec}B\to\operatorname{Spec}A$. Its map on <global sections> gives a <ring homomorphism>
$$
\phi:A=\Gamma(X,\mathcal O_X)\longrightarrow\Gamma(Y,\mathcal O_Y)=B.
$$
Locality of the <stalk> map implies, for every $a\in A$,
$$
a\in f(\mathfrak q)\quad\Longleftrightarrow\quad a/1\in\mathfrak m_{f(\mathfrak q)}\quad\Longleftrightarrow\quad\phi(a)/1\in\mathfrak qB_{\mathfrak q}\quad\Longleftrightarrow\quad\phi(a)\in\mathfrak q.
$$
Hence the point map must be $\mathfrak q\mapsto\phi^{-1}\mathfrak q$. On $D(a)$, its <structure sheaf> map must send $b/1$ to $\phi(b)/1$ and the inverse of $a$ to the inverse of $\phi(a)$. Thus it is precisely the <localization> map constructed above. Agreement on this basis proves agreement of the <morphisms of sheaves>. In particular, \b[the inducing ring homomorphism exists and is unique].
If $\phi$ is surjective, write $B=A/I$. The correspondence between <prime ideals> of $A/I$ and <prime ideals> of $A$ containing $I$ identifies $\operatorname{Spec}B$ homeomorphically with the closed subset $V(I)$: the <principal open subsets> correspond on both sides. Moreover, the <stalk> maps are the surjections $A_{\mathfrak p}\to(A/I)_{\mathfrak p/I}$, so $\mathcal O_X\to f_*\mathcal O_Y$ is surjective.
For the converse, it is important not to assume that <global sections> preserve an arbitrary surjection of <sheaves>. Here the <affine module-sheaf equivalence> supplies the extra information: on every $D(a)$,
$$
(f_*\mathcal O_Y)(D(a))=B_{\phi(a)}=B\otimes_AA_a.
$$
Thus $f_*\mathcal O_Y$ is the <quasi-coherent sheaf> associated with the $A$-<module> $B$, and the <cokernel sheaf> of $\mathcal O_X\to f_*\mathcal O_Y$ is associated with the <module> $C=\operatorname{coker}(A\to B)$, since <localization of a module> is exact. Surjectivity of the <morphism of sheaves> gives $C_{\mathfrak p}=0$ for every <prime ideal> $\mathfrak p$. This implies $C=0$: if $0\ne c\in C$, its proper annihilator lies in a <maximal ideal> $\mathfrak m$, and then $c/1\ne0$ in $C_{\mathfrak m}$. Therefore $A\to B$ is surjective. We have proved the <closed immersion criterion for affine schemes>:
$$
\boxed{\phi\text{ surjective}\ \Longleftrightarrow\ f\text{ is a homeomorphism onto a closed subset and }\mathcal O_X\twoheadrightarrow f_*\mathcal O_Y.}
$$
Back to article page