Added function to calculate in-degree of nodes.
Two variants. Slower one is commented