5 ms·
You could just run bfs from both starting and ending nodes until you find a node reachable from both the starting and ending nodes.
by 61u 2y ago
You could just run bfs from both starting and ending nodes until you find a node reachable from both the starting and ending nodes.
- 61u 2y agohttps://ideone.com/MGFwdo https://ideone.com/MGFwdo I am running BFS from only the starting node because the graph is symmetrical.