Show that if $f:X\to Y$ is a continuous function if and only if the graph of $f$ is a closed subset of $X\times Y$ 
Given a function $f:X\to Y$, we define the graph of $f$ as the set
  $$G(f)=\{(x,f(x)),x\in X\}$$ Show that if $X$ is compact then $f$ is a
  continous function if and only if $G(f)$ is a closed subset of
  $X\times Y$.

I know that a set $X$ is called compact when every open cover of $X$ have a finite subcover. Then I need to show that


*

*If $f$ is continous then $G(f)$ is a closed subset of $X\times Y$.

*If $G(f)$ is a closed subset of $X\times Y$ then $f$ is continous.
How I can show that?

Proof of the first assertion under the condition  $Y$ is a Hausdorff space:
Let $(x_i,f(x_i))$ be a net in $G(f)$ such that $(x_i,f(x_i))\to (x,y)$, then $x_i\to x$ and $f(x_i)\to y$, hence $y=\lim f(x_i)=f(x).$
If $Y$ is not Hausdorff, then the first assertion may fail: Let $X=\{0,1\}$ with discret topology, $Y=\{0,1\}$ with trivial topology, and $f=\operatorname{id}$.
It's easy to find the contradition.
A counterexample for the second assertion:
Let $X=[0,1]$ with euclidean topology, $Y=[0,1] $ with discret topology, and $f=\operatorname{id}_{[0,1]}$. Then $f$ is not continuous obviously, but the graph is closed. 
Indeed, suppose $(x_i,x_i)$ is a net in $G(f)$ such taht $(x_i,x_i)\to  (x,y)$, then $x_i\to x$ and $x_i\to y$, thus there exists some $i_0 $ such that $x_i=y\forall i\geq i_0$ since $\{y\}$ is a neiborhood of $y$, hence $x=y,$ i.e. $(x,y)\in G(f).$
However, the following is true:

Suppose $X$ is a compact Hausdorff space and $Y$ is a topological space, then $f:X\to Y$ is continuous iff the graph of $f$ is compact.
  See Graph of continuous function from compact space is compact. for the proof. 

Thank William for correcting mistakes.
