Hmm...I thought I had it but I don't. Let me try to think of something else. A common trick when doing things like this is to consider that map .
Hmm, obviously the tricks going to have to do something with if then the fibers of are going to be same.
I'm sorry for getting your hopes, I'll try to figure it out.
Let and let be an arbitrary point of the closure of . Let . We shall show that , which implies that is a closed set of Y.
Suppose to the contrary that . Then . Let U be an open neighborhood of . Then contains and , respectively. Let V and W be open components of such that and , where V and W are disjoint open sets. By hypothesis, f and g are continuous, so there exist open neighborhoods of such that and . This contradicts that is a point of the closure of . Thus and K is a closed set of Y.
To show that K is open in Y, you need to show that for any , there exists an open set contains and is contained in K. Let V and W be an open component of such that and , where U is an open neighborhood of . Since , we have . Thus K is an open set of Y.