Subspace union of connected components equivalent to continuous function to $\{0,1\}$

Let $A$ be a locally connected topological space and $B$ a subspace.
I want to prove the equivalence of the following two statements:

(i) $B$ is a union of connected components of $A$.
(ii) there is a continuous function $p:A\rightarrow \{0,1\}$ such that $p(b)=0$ for $b\in B$ and $p(b)=1$ for $b\notin B$.

What I know:
Locally connected means that for all $a\in A$ and neighbourhoods $N$ of $a$ there is a connected neighbourhood $N'$ such that $N'\subseteq N$.
A connected component of $A$ is a connected subspace $C$ such that there is no strict larger connected subspace $C\subset C'$ in $A$.
However, I dont see how these can help me prove the equivalence, maybe somebody can help?

HINT: The functions perhaps obscure what’s going on just a bit, so let’s get rid of them.

• Show that $(ii)$ is equivalent to the assertion that $B$ is a clopen (closed and open) subset of $A$.

Since components are always closed, a good first step would be to show that each component of $A$ is open.

• Show that if each component of $A$ is open, then each union of components of $A$ is clopen in $A$. Conclude that if each component of $A$ is open, then $(i)$ implies $(ii)$.

To show that each component of $A$ is open, suppose that $C$ is a component of $A$, and let $x\in C$; we want to show that $x$ has a nbhd contained in $C$. Since $A$ is locally connected, $x$ has some connected nbhd $N$.

• Show that $C\cup N$ is connected.
• Clearly $C\subseteq C\cup N$, so what can you infer about $N$?

All that remains is to show that $(ii)$ implies $(i)$.

• Show that every clopen subset of $A$ is a union of components.
• Thanks a lot, could you maybe complete your answer? Apr 14, 2016 at 7:15
• @Cognomen: This is already a pretty big hint. Can you do any of the five steps that I suggested? Apr 14, 2016 at 7:20
• The first, fourth and fifth aren't that clear to me. Apr 14, 2016 at 12:31
• @Cognomen: For the first, remember that if $f:X\to Y$ is continuous, then $f^{-1}[A]$ is closed in $X$ whenever $A$ is closed in $Y$, and $f^{-1}[A]$ is open in $X$ whenever $A$ is open in $Y$. Now consider the case $Y=\{0,1\}$ and $A=\{0\}$ or $A=\{1\}$. For the fourth, recall that the component containing a point $x$ is the largest connected subset of the space containing $x$. For the fifth, show that if $G$ is a clopen subset of $A$, and $K$ is a connected subset of $A$, then it’s impossible to have both $K\cap G$ and $K\setminus G$ non-empty. Apr 14, 2016 at 18:05
• Thank you again, I still have a few unclear things :( I hope you dont mind. For the third, aren't intersections of connected subsets always connected? For the fourth, does that mean that $N$ is empty? And could you explain the fifth a bit more? Apr 16, 2016 at 18:37