If union and intersection of two subsets are connected, are the subsets connected?

Suppose for a contradiction that $A$ is disconnected. Then there are closed, disjoint, non-empty subsets $S, T$ of $A$ such that $A=S\cup T$.
Since $A\cap B$ is connected, one of $B\cap S$ and $B\cap T$ must be empty, otherwise $A\cap B=(B\cap S)\cup (B\cap T)$. WLOG assume $B\cap S=\emptyset$.
Now, since $S$ and $T$ are closed in $A$ and $A$ is closed in $X$, $S$ and $T$ are closed in $X$. Therefore, $B\cup T$ and $S$ are closed non-empty subsets of $A\cup B$. Obviously, $(B\cup T)\cap S=\emptyset$ and $A\cup B=(B\cup T)\cup S$, so $A\cup B$ is disconnected, contradiction.


Let's use proof by contradiction. Without loss of generality, assume $A$ is not connected. Then (by definition) $A = A_1 \cup A_2$ such that $A_1 \subseteq U_1$, $A_2 \subseteq U_2$, $U_1 \cap U_2 = \emptyset$, and the sets $U_i$ are open. Can you proceed from there? Hint, you'll have to show one of $A \cap B$ or $A \cup B$ is in fact disconnected.