[proofplan]
We show the coincidence set $E := \{x \in X : f(x) = g(x)\}$ is closed in $X$ using the Hausdorff property of $Y$. Since $E$ contains the dense subset $A$, and the closure of a dense subset is the whole space, $E = X$. The key mechanism: $E$ is closed because its complement is open — for any $x$ with $f(x) \neq g(x)$, the Hausdorff property separates $f(x)$ and $g(x)$ by disjoint open sets, whose preimages yield a neighbourhood of $x$ in $X \setminus E$.
[/proofplan]
[step:Define the coincidence set and show it is closed]
Define the coincidence set
\begin{align*}
E := \{ x \in X : f(x) = g(x) \}.
\end{align*}
We show $X \setminus E$ is open. Let $x \in X \setminus E$, so $f(x) \neq g(x)$. Since $Y$ is Hausdorff, there exist disjoint open sets $V_1, V_2 \subset Y$ with $f(x) \in V_1$ and $g(x) \in V_2$. Define $W := f^{-1}(V_1) \cap g^{-1}(V_2)$. Since $f$ and $g$ are continuous, both $f^{-1}(V_1)$ and $g^{-1}(V_2)$ are open in $X$, so $W$ is open in $X$, and $x \in W$. For any $z \in W$, $f(z) \in V_1$ and $g(z) \in V_2$; since $V_1 \cap V_2 = \varnothing$, $f(z) \neq g(z)$, so $z \in X \setminus E$. Hence $W \subset X \setminus E$, confirming that $X \setminus E$ is open. Therefore $E$ is closed.
[guided]
We want to show $f = g$ on all of $X$, knowing they agree on the dense subset $A$. The strategy is to show that the set where $f$ and $g$ agree is closed, and then use density.
Define the coincidence set $E := \{x \in X : f(x) = g(x)\}$. We claim $E$ is closed, or equivalently, $X \setminus E$ is open.
Take any $x \in X \setminus E$. Then $f(x) \neq g(x)$ — these are two distinct points of $Y$. Since $Y$ is Hausdorff, the separation axiom provides disjoint open sets $V_1, V_2 \subset Y$ with $f(x) \in V_1$ and $g(x) \in V_2$, and $V_1 \cap V_2 = \varnothing$.
Now we pull back to $X$. Define $W := f^{-1}(V_1) \cap g^{-1}(V_2)$. Since $f$ is continuous, $f^{-1}(V_1)$ is open in $X$. Since $g$ is continuous, $g^{-1}(V_2)$ is open in $X$. The intersection $W$ of two open sets is open, and $x \in W$ (since $f(x) \in V_1$ and $g(x) \in V_2$).
We verify $W \subset X \setminus E$: for any $z \in W$, we have $f(z) \in V_1$ and $g(z) \in V_2$. Since $V_1$ and $V_2$ are disjoint, $f(z) \neq g(z)$, so $z \notin E$.
We have shown that every point of $X \setminus E$ has an open neighbourhood contained in $X \setminus E$. Hence $X \setminus E$ is open, and $E$ is closed.
This is precisely where the Hausdorff hypothesis on $Y$ is consumed. If $Y$ were not Hausdorff — for example, $Y$ with the indiscrete topology — distinct points $f(x)$ and $g(x)$ could not be separated, and the argument would fail. Indeed, the theorem is false without the Hausdorff condition: take $Y = \{0, 1\}$ with the indiscrete topology, $X = \mathbb{R}$, $A = \mathbb{R} \setminus \{0\}$, $f \equiv 0$, and $g = \mathbb{1}_{\{0\}}$. Then $f|_A = g|_A = 0$ but $f(0) \neq g(0)$.
[/guided]
[/step]
[step:Use density of $A$ to conclude $E = X$]
The hypothesis $f|_A = g|_A$ means $A \subset E$. Since $A$ is dense in $X$, the closure $\overline{A} = X$. Since $E$ is closed and $A \subset E$, we have $X = \overline{A} \subset \overline{E} = E \subset X$. Therefore $E = X$, which means $f(x) = g(x)$ for all $x \in X$.
[guided]
We now combine the two ingredients. The hypothesis $f|_A = g|_A$ states that $f(a) = g(a)$ for every $a \in A$, meaning $A \subset E$. Since $A$ is dense in $X$, we have $\overline{A} = X$.
The closure operation is monotone: $A \subset E$ implies $\overline{A} \subset \overline{E}$. Since $E$ is closed (established in the previous step), $\overline{E} = E$. Therefore
\begin{align*}
X = \overline{A} \subset \overline{E} = E \subset X,
\end{align*}
which forces $E = X$. Hence $f(x) = g(x)$ for every $x \in X$.
Both hypotheses play distinct roles: density of $A$ ensures $\overline{A} = X$, so the agreement set cannot be a proper closed subset; the Hausdorff property of $Y$ ensures that the agreement set is closed at all. Without either, the conclusion can fail.
[/guided]
[/step]