It's currently possible to create an undirected graph by adding edges from both u to v and v to u for all connected pairs (u, v). This requires a bit of extra space and more effort to set up.
The simplest solution I can think of is to add an undirected flag to Graph. When enabled, (v, u) would be added automatically when (u, v) is added. This would still require extra space but wouldn't require any other changes (e.g., to the shortest path algorithm).
It's currently possible to create an undirected graph by adding edges from both
utovandvtoufor all connected pairs(u, v). This requires a bit of extra space and more effort to set up.The simplest solution I can think of is to add an
undirectedflag toGraph. When enabled,(v, u)would be added automatically when(u, v)is added. This would still require extra space but wouldn't require any other changes (e.g., to the shortest path algorithm).