Add different maps for incoming edges and outgoing edges for easy book keeping node info of all edges and simplify the algo.