Adding check to prevent adding multiple edges between nodes.
After finishing homework for week4.