Let $X\subset\mathbb{R}^n$ be a not connected set and $A,B\subset X$ disjoint connected components of $X$. How to prove that there are disjoint open sets $U,V\subset\mathbb{R}^n$ such that $$X\subset U\cup V$$ $$A\subset U\;,\;B\subset V$$
What happens if $X$ is compact?
Any hint would be appreciated.