Eugene E. answered 08/10/23
Math/Physics Tutor for High School and University Students
Without loss of generality, suppose A and B are both open. To see that A is connected, it suffices to show that every continuous function from A to the discrete space {0,1} is constant. To this end, let f : A → {0,1} be a arbitrary continuous function. The restriction of f to the open subset A ∩ B is continuous; connectedness of A ∩ B forces the restriction to be constant, say, f(x) = 0 for all x ∈ A ∩ B. By the pasting lemma, the function F : A ∪ B → {0,1} given by F(x) = f(x) for all x ∈ A and F(x) = 0 for all x ∈ B, is continuous. Connectedness of A ∪ B implies F is constant. Thus F(x) = 0 for all x ∈ A ∪ B. In particular, f is constant (identically equal to 0). Since f was arbitrary, this shows that A is connected. The same argument shows that B is connected as well.