Shortest walk visiting all nodes
Your task
You are given an undirected, connected graph of n nodes (0..n-1) as an adjacency list. Return the length of the shortest walk that visits every node at least once. You may start and stop at any node, and you may revisit nodes and re-traverse edges (each edge traversed counts as 1 step). For n==1 the answer is 0.
Examples
shortest_path_all_nodes(graph: list[list[int]]) -> intExample 1
Input
shortest_path_all_nodes([[1, 2, 3], [0], [0], [0]])Output
4