# Suppose $H$ and $K$ are closed such that $H \cup K$ and $H \cap K$ are connected. Prove that $H$ and $K$ are connected.

Let $X$ be a topological space. Suppose $H$ and $K$ are closed subsets of $X$ such that $H \cup K$ and $H \cap K$ is connected. Prove that $H$ and $K$ are connected.

My work: Assume for the sake of a contradiction that exactly one $H$ or $K$ are not connected. Then WLOG let $H$ be not connected and so $H = A \cup B$ for nonempty disjoint subsets of $X$. But then,

$$H \cup K = \left(A \cup B \right) \cup K$$ $$H \cap K = \left(A \cup B \right) \cap K = \left(H \cap A\right) \cup \left(H \cap B\right)$$ We also have that $Cl(K)=K$ and $Cl(H)=H$ since $H$ and $K$ are closed. Also that $Cl(A) \cap B = A \cap Cl(B) = \emptyset$. I'm unsure how to reach a contradiction from this. Any help is appreciated, thanks!

Nonempty disjoint closed subsets $A,B$ would be excellent. Let $H=A \cup B$
Hint: since $H \cap K \subset H$ implies that it belongs to precisely one of $A$ or $B$ since it is connected, and its intersection with either of them would constitute a seperation otherwise. Suppose the intersection belongs to $A$. Then it is disjoint from $B$. What can you say about $(K \cup A) \cup B$?
Let $\mathcal{D}:=\{0,1\}$ be equipped with the discrete topology. It suffices to prove that every continuous map $f: H \to \mathcal{D}$ is constant (for $K$ just repeat the argument).
Therefore, let $f: H \to \mathcal{D}$ be a continuous map. Since restrictions are continuous, $f|_{H \cap K}:H \cap K \to \mathcal{D}$ is continuous. By hypothesis, $H \cap K$ is connected, and hence $f|_{H \cap K}$ is constant, say equal to $a$.
Define $g: H \cup K \to \mathcal{D}$ by $g(x)=f(x)$ if $x \in H$ and $g(x)=a$ if $x \in K$. By the pasting lemma, $g$ is continuous. Since $H \cup K$ is connected, $g$ is constant. Therefore, $g|_{H}$ is constant. But $g|_H=f$.