3. Given $x \in \mathbf{R}, y \in \mathbf{R}^{+}, A=\left\{x^{2}+x+1,-x,-x-1\right\}, B=$ $\left\{-y,-\frac{y}{2}, y+1\right\}$. If $A=B$, then the value of $x^{2}+y^{2}$ is ( ).
A. 4
B. 5
C. 10
D. 25
3. B.
Since $(x+1)^{2} \geqslant 0$, we have $x^{2}+x+1 \geqslant -x, x^{2}+x+1>0$. By the distinctness of elements, $x^{2}+x+1 \neq -x$, thus $x \neq -1, x^{2}+x+1>-x>-x-1$. Also, since $y \in \mathbf{R}^{+}$, we have $y+1>-\frac{y}{2}>-y$. Because $A=B$, we have $x^{2}+x+1=y+1, -x=-\frac{y}{2}, -x-1=-y$, which gives $x=1, y=2$.