The image of the diagonal map in scheme

Let $X\rightarrow S$ be a separated morphism of schemes, that is, the diagonal map $\Delta:X\rightarrow X\times_S X$ is a closed inmersion. In general (see Closure of image of diagonal morphism of S-scheme) it is not true that $\Delta(X)=\{z\in X\times_S X:p_1(z)=p_2(z)\}$ where $p_1,p_2:X\times_SX\rightarrow X$ are the projections. Now let $Y$ be another $S$-scheme and let $f,g:Y\rightarrow X$ be $S$-morphisms with product $f\times g:Y\rightarrow X\times_SX$. If $y\in Y$ satisfies $f(y)=g(y)$, can we ensure that $f\times g(y)\in\Delta(X)$?.

I am asking this question because I've been stack for a long with Exersice 4.2 of Hartshorne's book (Chap 2) and searching on the web I saw that everybody assume this fact.

Many thanks!


Think functorially (i.e. don't think in terms of points). 2.4.2 of Hartshorne wants to show that $f,g: X \to Y$ are the same if $X$ is reduced, $Y$ is separated, and $f,g$ agree on an open dense subset $U$. I suspect you are trying to say something like $f \times g(U) \subset \Delta (X)$, but you don't need to do this pointwisely. Instead, try to think about this:

Consider the fibre product of the diagram $f \times g: Y \to X \times_S X$ and $\Delta:X \to X \times_S X$. You would get $j: (f \times g)^{-1}(\Delta(X)) \to Y$ is a closed immersion. You want to get the inclusion $i: U \to Y$ factors through $j$. For this, use the universal property of fibre product, then you would want to get a map $h: U \to X$ such that $\Delta \circ h = (f \times g) \circ j$. That $f$ and $g$ agree on $U$ would give you a natural candidate for $h$ - what should it be?