calculate the indegree and outdegree