Let $T$ be tree of order (number of vertices) $p$ and with $p_i$ vertices of degree $i$ for each $i\in \{1,\dots, p-1\}$. I am asked to prove that the following equation is satisfied:
$p_1=\sum_{i=3}^{p-1}(i-2)p_i+2$
Since $T$ has order $p$, $p_{p-1}$ can only be $0$ or $1$. If it is $1$, i.e., there is a vertex of degree $p-1$, then every other vertex is a leaf connected to it. Hence $p_1=p-1$ and $p_i=0$ for $1<i<p-1$. Introducing this data into the equation we get
$p-1=(p-3)+2$
which is true. Then I can assume that $p_{p-1}=0$.
Now I don't know how to go on. Is there any direct approach in which I could avoid distinguishing cases for the possible values of $p_i$?
I also tried using the handshaking lemma and the fact that the number of edges equals $p-1$, but I got nothing similar to the equation I'm looking for.
The equation $$p_1=\sum_{i=3}^{p-1}(i-2)p_i+2$$ can be rewritten as $$\sum_{i=1}^{p-1} (i-2) p_i + 2 = 0.$$ (The coefficient of $p_1$ is $-1$, and the coefficient of $p_2$ is $0$, so $p_1$ and $p_2$ fit the pattern of the sum already.)
The $-2$ in the factor $i-2$ seems to have no combinatorial meaning, so it makes sense to rewrite the equation further as $$ \sum_{i=1}^{p-1} i p_i + 2 = \sum_{i=1}^{p-1}2p_i. $$ Now think about what both of the sums in this equation count.