Simple graph

Are your edges meant to be directional? Relatedly, are multiple edges between the same two nodes allowed in your graph? If yes, then your code looks fine here, but if that wasn't your intention, this is something you're not checking for and could cause a bug.