For closed subsets $A,B \subseteq X$ with $X = A \cup B$ show that $f \colon X \to Y$ is continuous iff $f|_A$ and $f|_B$ 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
 A: $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.
A: $X = (A - B) \cup (B-A) \cup (A \cap B)$
$(A - B) \cap (B - A) = \emptyset$
$(B - A) \cap (A \cap B) = \emptyset$
$(A \cap B) \cap (A - B) = \emptyset$  
Since $X = (A - B) \cup B$ and $B$ is closed in $X$, $A - B$ is open in $X$.
Since $X = (B - A) \cup A$ and $A$ is closed in $X$, $B - A$ is open in $X$.
Let $x_0 \in X$ .
Case 1
If $x_0 \in A - B$, then there exists $\delta_1 > 0$ such that $\{ x \in X \text{ }|\text{ } d_X(x, x_0) < \delta_1 \} \subset A - B$ because $A - B$ is open in $X$.  
Let $\epsilon$ be an arbitrary positive real number.  
$f_{|A}:A \rightarrow Y$ is continuous. So there exists $\delta_2 > 0$ such that $d_A(x, x_0) < \delta_2 \implies d_Y(f(x), f(x_0) < \epsilon$  
Let $\delta := \min(\delta_1, \delta_2)$.  
$\{ x \in X \text{ }|\text{ } d_X(x, x_0) < \delta \} = \{ x \in A \text{ }|\text{ } d_A(x, x_0) < \delta \}$
because $\{ x \in X \text{ }|\text{ } d_X(x, x_0) < \delta \} \subset A$.  
And $d_A(x, x_0) < \delta \implies d_Y(f(x), f(x_0)) < \epsilon$.  
So $d_X(x, x_0) < \delta \implies d_Y(f(x), f(x_0)) < \epsilon$.  
Case 2
If $x_0 \in B - A$, for any real number $\epsilon > 0$, there exists a real number $\delta > 0$ such that  $d_X(x, x_0) < \delta \implies d_Y(f(x), f(x_0)) < \epsilon$. The proof is similar to the case 1.  
Case 3
Let $x_0 \in A \cap B$.
Let $\epsilon > 0$ be an arbitrary positive real number.
$f_{|A}:A \rightarrow Y$ and $f_{|B}:B \rightarrow Y$ are continuous.  
So there exist $\delta_1 > 0, \delta_2 > 0$ such that
$d_A(x, x_0) < \delta_1 \implies d_Y(f(x), f(x_0)) < \epsilon$ and
$d_B(x, x_0) < \delta_2 \implies d_Y(f(x), f(x_0)) < \epsilon$.  
Let $\delta := \min(\delta_1, \delta_2)$.  
$\{x \in A \text{ }|\text{ } d_A(x, x0) < \delta\} \cup \{x \in B \text{ }|\text{ } d_B(x, x0) < \delta\} = \{x \in X \text{ }|\text{ } d_X(x, x0) < \delta\}$.  
$x \in \{x \in A \text{ }|\text{ } d_A(x, x0) < \delta\} ⇒ d_Y(f(x), f(x0)) < \epsilon$.
$x \in \{x \in B \text{ }|\text{ } d_B(x, x0) < \delta\} ⇒ d_Y(f(x), f(x0)) < \epsilon$.  
So  
$x \in \{x \in X \text{ }|\text{ } d_X(x, x0) < \delta\} ⇒ d_Y(f(x), f(x0)) < \epsilon$.  
So  
$f$ is continuous.
