Fix bugs caused by nx.shortest_path(same key may appear several times in the return value)