function to calculate the degree of a vertex