Continuous mapping into a Hausdorff space Please give your comment and help with the following exercise.

[=>]: Let $y_1, y_2 \in Y, y_1 \neq y_2$.
Since $f$ is surjective, $y_1 = f(x_1), y_2 = f(x_2)$ for some $x_1,x_2 \in X$.
Since $Y$ is Hausdorff, there exist in $Y$ open neighborhoods $N(y_1), N(y_2)$ of $y_1,y_2$ respectively, such that $N(y_1) \cap N(y_2) = \emptyset$.
Since $f$ is continuous, $f^{-1}(N(y_1)) \text{ and } f^{-1}(N(y_2))$ are open in $X$, necessarily disjointed and contain $x_1, x_2$, respectively.
It's here that I got stuck. My idea is to use what I know about $f^{-1}(N(y_1)) \text{ and } f^{-1}(N(y_2))$ to show that $(X \times X)\backslash R$ is open, hence $R$ is closed. But I don't know how to proceed.
[<=]: I might need some hints here also.
 A: You have to show that if $Y$ is Hausdorff, a certain subset of $X\times X$ is closed. So you are not going to begin by taking two distinct elements of $Y$. 
Take $(x_1, x_2)$ in $(X\times X)\setminus R$, then by definition $f(x_1)\neq f(x_2)$, so you have two open neighborhoods $U, V$ of $f(x_1)$ resp. $f(x_2)$ in $Y$, such that $U\cap V=\emptyset$.
Then, $U^\prime:=f^{-1}(U)$ and $V^\prime:=f^{-1}(V)$ are open neighborhoods of $x_1$ resp $x_2$, and you have that $f(U^\prime)\cap f(V^\prime)=\emptyset$.
So, $U^\prime\times V^\prime$ is an open neighborhood of $(x_1, x_2)$ in $(X\times X)\setminus R$.
I let you try the second part.
A: If $Y$ is Hausdorff, to show that $R$ is closed, we can show that $R'=X \times X \setminus R$ is open. Let $(x_1, x_2)$ be an arbitrary point in $R'$. Then by definition, this means that $y_1=f(x_1) \not= f(x_2)=y_2$. Because $Y$ is Hausdorff, this means there exist disjoint open sets $U$ and $V$ in $Y$ such that $y_1 \in U$ and $y_2\in V$. By continuity of $f$, we have that $f^{-1}(U)$ and $f^{-1}(V)$ are open in $X$ and they are disjoint so that $f^{-1}(U) \times f^{-1}(V)$ is open in $R'$ (Why is it open in $R'$? Because first $f^{-1}(U) \times f^{-1}(V)$ is open in $X \times X$ and being contained in $R'$ gives us that it is open in the subspace $R'$ of $X \times X$, which has open sets of the form $E \times F \cap R'$, where $E \times F$ is open in $X \times X$. We can also write $f^{-1}(U) \times f^{-1}(V) \cap R'= f^{-1}(U) \times f^{-1}(V)$ to see that it is open in $R'$.) and $(x_1, x_2) \in f^{-1}(U) \times f^{-1}(V)$. This means that $R'$ is the union of open sets hence open itself.
Conversely, assume that $R$ is closed in $X \times X$. Let $f(x_1) = y_1, f(x_2)=y_2$ be two distinct points in $Y$ (here we're using surjectivity of $f$). We can then say that $(x_1, x_2) \in A \times B \subseteq R'$, where $A$, $B$ are open in $X$. Then $f(A)$ and $f(B)$ are open sets in $Y$ (because $f$ is open) containing $y_1$ and $y_2$, respectively. We show that $f(A) \cap f(B)$ is disjoint. Suppose $y \in f(A) \cap f(B)$. Then $y=f(a)=f(b)$ for $a \in A$ and $b\in B$. Hence $(a, b) \in R$, which is a contradiction because $A \times B \cap R = \emptyset$.
