solve calculating degree of nodes in graph