[proofplan]
We use the characterisation from the [equivalent characterisations of connectedness](/theorems/294): a space is connected if and only if every continuous function to $\mathbb{Z}$ is constant. Given $f: S \to \mathbb{Z}$ continuous on the union $S = \bigcup \mathcal{A}$, its restriction to each connected member of $\mathcal{A}$ is constant, and the pairwise intersection condition forces all these constants to agree.
[/proofplan]
[step:Show that every continuous $\mathbb{Z}$-valued function on $\bigcup \mathcal{A}$ is constant]
Let $S = \bigcup_{A \in \mathcal{A}} A$ and let $f: S \to \mathbb{Z}$ be continuous (where $\mathbb{Z}$ carries the discrete topology). Fix any $A_0 \in \mathcal{A}$. Since $A_0$ is connected and $f|_{A_0}: A_0 \to \mathbb{Z}$ is continuous, the [equivalent characterisation of connectedness](/theorems/294) (condition (3)) implies $f$ is constant on $A_0$; denote this value by $c$.
Let $B \in \mathcal{A}$ be arbitrary. Since $A_0 \cap B \neq \varnothing$ by hypothesis, choose $p \in A_0 \cap B$. Then $f(p) = c$ (since $p \in A_0$). Since $B$ is connected and $f|_B$ is continuous, $f$ is constant on $B$, and its constant value equals $f(p) = c$. Therefore $f \equiv c$ on $B$.
Since $B \in \mathcal{A}$ was arbitrary, $f \equiv c$ on all of $S$. By the [equivalent characterisation of connectedness](/theorems/294) (condition (3) $\Rightarrow$ condition (1)), $S$ is connected.
[guided]
The characterisation (3) from the [equivalent characterisations of connectedness](/theorems/294) says: $X$ is connected if and only if every continuous function $X \to \mathbb{Z}$ is constant. This is often the most efficient way to prove connectedness, because it reduces the problem to showing a single function is constant.
Let $f: S \to \mathbb{Z}$ be continuous where $S = \bigcup_{A \in \mathcal{A}} A$. Fix any $A_0 \in \mathcal{A}$. Since $A_0$ is connected, $f|_{A_0}: A_0 \to \mathbb{Z}$ is continuous with discrete codomain, so it is constant. Call the value $c = f(p)$ for any $p \in A_0$.
Now let $B \in \mathcal{A}$ be arbitrary. The pairwise intersection hypothesis gives a point $p \in A_0 \cap B$. This point serves as a "bridge": $f(p) = c$ because $p \in A_0$. Since $B$ is connected and $f|_B$ is continuous into $\mathbb{Z}$, $f$ is constant on $B$. Its constant value must be $f(p) = c$.
Since $B \in \mathcal{A}$ was arbitrary, $f \equiv c$ on every member of $\mathcal{A}$, hence $f \equiv c$ on all of $S$. By characterisation (3), $S$ is connected.
The pairwise intersection condition is essential: without it, different members of $\mathcal{A}$ could carry different constant values of $f$, and the union would be disconnected. The condition ensures that the single value $c$ propagates from $A_0$ to every other member through shared points.
[/guided]
[/step]