Updated input to handle undirected graphs.