Compact topological space with closed graph implies continuity

Let $X,Y$ be topological spaces and $f:X \rightarrow Y$

If $Y$ is compact and $G(f)$ (graph of $f$) is closed, show that $f$ is continuous.

I consider an open set in $X$, and as $G(f)$ is closed, $(X \times Y)-G(f)$ is open. And I guess I need to do something here. Then I can get some open sets. Also, I notice that compact is something relate to "finite". I guess I can use the compactness to do finite intersection or union and get the result finally.

But what should I do in the middle or I am not even on a right track.


Let $X,Y$ be topological spaces, $Y$ compact. Let $f: X \rightarrow Y$ be a map. Assume that $G(f):=\{ (x,y) \in X \times Y : y=f(x) \}$ is closed in $X\times Y$.

Let $A\subseteq Y$ be a closed set. We define

$$ \tilde{A} := \left( X\times A \right) \cap G(f),$$

which is a closed subset of $X\times Y$. Recall that, due to the fact that $Y$ is compact, the projection on $X$, $\pi_X: X\times Y \rightarrow X, (x,y) \mapsto x$ is a closed map (see here Projection map being a closed map). Hence, $\pi_X(\tilde{A})=f^{-1}(A)$ is a closed subset of $X$. This yields the continuity of $f$.