Given graph $G(V,E)$. Every vertice $v$ has its weight $w(v)$. I want to work with $$\sum_{(u,v)\in E}w(u)w(v)$$ I think it should many good approaches to this object? Furhermore, is there method of calculating this sum via incidence matrix? Incidence matrix is $|V|\times|V|$ $(0,1)$-matrix with entries $a(u,v)$, such that $$ a(u,v)= \begin{cases} 1 & (u,v)\in E \\ 0 & otherwise \end{cases} $$