Lexicographically smallest Eulerian path
Your task
Given a directed multigraph on nodes 0..n-1 as a list of edges [u, v], reconstruct the lexicographically smallest Eulerian path: a sequence of node ids that uses every edge exactly once, where among all valid Eulerian paths you return the one whose node sequence is smallest in dictionary order. Return the sequence as a list of node ids (length = number of edges + 1). If no Eulerian path exists, return an empty list. Constraints: up to 60 edges; the graph may have parallel edges.
Examples
euler_path(n: int, edges: list[list[int]]) -> list[int]Example 1
Input
euler_path(3, [[0, 1], [1, 2], [2, 0], [0, 2]])Output
[0, 1, 2, 0, 2]