Problem:
Suppose $X$ is a topological space. Let $(A_n)_n$ be a sequence of connected subsets of $X$, for which, $A_n\cap A_{n+1}\neq \varnothing$. Then, $A=\bigcup_n A_n$ is connected.
My attempt: Suppose $\bigcup_n A_n$ is disconnected, so there exists a non-constant continuous function $f:\bigcup_nA_n\rightarrow \{ 0,1 \}$ , where the codomain is equipped with the discrete topology. Then, since each $A_n$ is connected, we have that $f|_{A_n}$ is constant. Since $A_n\cap A_{n+1}\neq \varnothing$ for each n, and each $A_n$ is connected, $f|_{A_n}=f|_{A_j}$ for each $n,j$. Hence, $f$ is constant.
My attempt to make it clearer:
If $\bigcup_nA_n$ was disconnected, there would exist a non-constant, continuous function $f:\bigcup_n A_n\rightarrow \{ 0,1 \}$. Observe that since each $A_n$ is connected, $f|_{A_n}$ being continuous would imply that $f|_{A_n}$ is constant. Since $A_n$ and $A_{n+1}$ always share a common element, implies that for any $x\in X$, $f|_{A_1}(x)=f|_{A_2}(x)=..1$ (say). Now,considering $f:\bigcup_nA_n \rightarrow \{0,1\}$, we observe that for any $x\in \bigcup_nA_n$, $x\in A_m$, for some $m$, and so $f(x)=f|_{A_m}(x)=1$
Is this right?
Suppose $f\colon\bigcup A_n \to \{0,1\}$ is continuous. Since $A_1$ is connected, $f|_{A_1}$ must be constant, say $0$. Now, let's suppose that $f|_{A_n} = 0$ for some $n\in\Bbb N$. There is some $x\in A_n\cap A_{n+1}$, so $f(x)=0$. Since $A_{n+1}$ is connected, it follows that $f|_{A_{n+1}} = 0$. Therefore, by induction, we have shown that $f|_{A_n} = 0$ for all $n\in\Bbb N$, which means that $f$ is constant on $\bigcup A_n$. This proves that $\bigcup A_n$ must be connected.