# continuity of function where the functions restricted to certain closed subspaces are continuous

I was just trying to solve an exercise in Munkres' "Analysis on Manifolds" to get better at continuous functions and topology in $\mathbb{R}^{n}$, and i got stuck. Here it is:
Let $X = A \cup B$, $A$ and $B$ are subspaces of $X$. Let $f:X \rightarrow Y;$ suppose that the restricted functions $f|A:A \rightarrow Y$ and $f|B:B \rightarrow Y$ are continuous. Show that if both $A$ and $B$ are closed in $X$, then $f$ is continuous.

Our definition of continuity is:
$f$ is continuous at $x \in X$ if for each open set $V$ of $Y$ containing $f(x)$, there is an open set $U$ of $X$ containing $x$ such that $f(U) \subset V$. $f$ is continuous if it is continuous at each point of its domain.

What I've tried so far:
Suppose $A$ and $B$ are closed in $X$. Suppose $A \cap B = \emptyset$. Then $X -A$ is open in $X$. But $X - A = B$ which is closed in $X$, which is a contradiction. Hence, $A \cap B \ne \emptyset$. I'm not sure if this will be useful in the problem or not.
if $x \in X$, then it's either in $A$ or in $B$. Suppose without loss of generality that it's in $A$. Then for all open sets $V$ of $Y$ s.t. $f(x) \in V$, $\exists$ an open set $U_{1}$ of $A$ s.t. $U_{1} \subset A, a \in U_{1}$ and $f(U_{1}) \subset V$. This is almost what we want, except that we want to find an open set $U$ of $X$ s.t. $U \subset A, a \in U$ and $f(U) \subset V$. This is because $U_{1}$ being open in $A$ does not necessarily mean that it's open in $X$ because $A$ is closed in $X$. (i know how to expand this argument out if needed) My idea now is to try to find a subset $U$ of $U_{1}$ such that $U$ is open in $X$. We have two cases:
(1) $U_{1}$ does not intersect the boundary of $A$.
(2) $U_{1}$ intersects the boundary of $A$.
Now i'm not sure what to do.
I'm wondering if it would help to investigate the relationship between Bd(A) and Bd(B).. In any case(no pun intended), any help/advice would be greatly appreciated. :)

Sincerely,

Vien

-

$f$ is continuous if and only if $f^{-1}(U)$ is open for every open subest $U$ of $Y$. Hence $f$ is continuous if and only if $f^{-1}(F)$ is closed for every closed subset $F$ of $Y$.
Let $F$ be a closed subset of $Y$. Let $G = f^{-1}(F)$. It suffices to prove that $G$ is closed. $G = G \cap X = G \cap (A \cup B) = (G \cap A) \cup (G \cap B)$. Since $f|A$ is continuous, $G \cap A$ is closed in $A$. Since $A$ is closed, $G \cap A$ is closed. Similarly $G \cap B$ is closed. Hence $G = (G \cap A) \cup (G \cap B)$ is closed.