use a set for nodes and always add each node when adding an edge