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?
 A: Your purported equivalence can fail in both directions, if we don't add extra assumptions on $Y$.
The implication $G(f)$ closed implies $f$ continuous can fail for compact $X$:
Let $X = [0,1]$ in the cofinite topology; this is a compact space. 
Let $Y = [0,1]$ in the discrete topology.
Define $f(x) =x$ from $X$ to $Y$, then $f$ is not continuous, as $f^{-1}[\{0\}] = \{0\}$ is not open in $X$, but $\{0\}$ is open in $Y$.
But $G(f)$ is closed in $X \times Y$: suppose $(p,q) \notin G(f)$, then $q \neq p$ and then the set $(X\setminus\{q\}) \times \{q\}$ is an open neighbourhood of $(p,q)$ that misses $G(f)$.
We can drop the compactness of $X$ and replace it by the compactness of $Y$; then the implication does hold:
Suppose then that $G(f)$ is closed. Kuratowski's theorem says that $\pi_X: X \times Y \to X$ is a closed map for compact $Y$.
Let $C \subseteq Y$ be closed and check that:
$$f^{-1}[C] = \pi_X[(X \times C)\cap G(f)]$$ which is the image of a closed set of $X \times Y$ under $\pi_X$, so $f^{-1}[C]$ is closed for all closed $C \subseteq Y$, meaning that $f$ is continuous.
The implication $f$ continuous implies $G(f)$ closed can also fail for compact $X$ (even for compact $Y$): 
Let $X = \{0,1\}$ in the discrete topology, $Y$ the same set in the indiscrete (trivial) topology. Again $f$ is the identity. This $f$ is continuous, but a basic open neighbourhood $(0,1)$ contains $\{0\} \times \{0,1\}$ which intersects $G(f)$. So $(0,1) \in \overline{G(f)} \setminus G(f)$, so $G(f)$ is not closed.
If we add the condition that $Y$ is Hausdorff, we don't need compactness of $X$ at all to see that $f: X \to Y$ continuous implies $G(f)$ is closed. This then always holds.
A: 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.
A: The problem statement, as been shown, has some problems.
Instead, I suggest it be replaced by proving the following.  
If Y is Hausdorff and f:X -> Y is continuous, then G(f) is closed.
If Y is compact and G(f) is closed, then f:X -> Y is continuous.  
For the second one, show the inverse image of a closed set is closed.
Useful for that is pi_1:XxY -> X is closed.  
Theorem
compact Y implies pi_1:XxY -> X closed.
Proof.
Let K be a closed subset of XxY.
lemma:  U \cap pi_1(K) empty iff UxY \cap K empty  
Assume x not in pi_1(K).  Hence
{x} \cap pi_1(K) and {x}xY \cap K are empty  .  
By the tube lemma there's
some open U,V with {x}xY subset UxV subset (XxY)\K.  
Whereupon UxY \cap K and U \cap pi_1(K) are empty since V = y  .
As x in U, x not in cl pi_1(K).  
Thusly cl pi_1(K) subset pi_1(K) which shows pi_1(K) is closed.    
There is a converse.
Y compact iff for all X, pi_1:XxY -> X closed.  
A: This answer starts out as providing hints/techniques that will be fleshed out to a full answer as I get the time. It is hoped that the details will be more than sufficient for the interested reader to follow.

Let $X$ and $Y$ be two topological spaces. For any $y_0 \in Y$, we have the constant mapping 
$f_{y_0}: x\mapsto y_0$
Note that the $\text{Graph of } f_{y_0} = X \times \{y_0\}$, and we regard it as a subspace of the topological product $X \times Y$.
The reader is advised to review the definitions of open cylinder and cylinder set in the product topology.
Proposition 1: $Y$ is Hausdorff $\Leftarrow\Rightarrow$ the graphs of any two different constant mappings can be separated by open sets in $X \times Y$.
Proof: The '$\Rightarrow$'direction is very easy by using open cylinders and remembering how to intersect Cartesian products.
For the '$\Leftarrow$'direction, let $U_{y_o}$ (resp. $U_{y_1}$) be an open set containing  the $\text{Graph of } f_{y_0} = X \times \{y_0\}$ (resp. $\text{Graph of } f_{y_1} = X \times \{y_1\}$) such that
$U_{y_o} \cap U_{y_1} = \emptyset$
Select any point $x$ in $X$. Corresponding to this point are the two points $(x,y_o) \in U_{y_o}$ and $(x,y_1) \in U_{y_1}$. We know both of these two points are contained in cylinder sets contained in the corresponding open $U \text{ Set}$. As subsets of disjoint sets, these cylinder sets must also be disjoint. We know that $x$ appears as a first coordinate in both of these (open cartesian) cyclinder sets. According to the Cartesian Product of Intersections rule, the 2nd coordinate opens sets containing $y_0$ and $y_1$ for each cylinder set must be disjoint, so $Y$ is Hausdorff.

Proposition 2: Let $X$ and $Y$ be two topological spaces. Then
$f: X \to Y$ is continuous iff the mapping $x \mapsto (x,f(x))$ from $X$ into the product space $X \times Y$ is continuous.
