Identity for sum of squares of vertex degrees in graph I am trying to understand this identity but I don't see how they count the same thing:
Given a graph $G$
\begin{align*}
\sum_{x \in V(G)} d(x)^2 = \sum_{xy \in E(G)} d(x) + d(y)
\end{align*}
I am looking for a good explanation of why this identity is true.

Consider a specific vertex $x\in V(G)$ and see how much it contributes to the sum of each side of the equation.
On the LHS, it is clear to see that it contributes $d(x)^2$ to the overall total.
On the RHS however, it is less apparent.  However, we can see that $x$ will be present in exactly $d(x)$ different edges.  For each of those edges, the amount of $d(x)$ will be added (in addition to the degree of the other end, however those can be grouped up when considering that vertex's contribution)
As such, there will be $d(x)$ occurrences of adding $d(x)$ to the total sum for each specific $x$.  In other words, each $x$ contributes $d(x)\cdot d(x)=d(x)^2$ to the total sum.
Hence, the sums are the same.
