Eulerian circuit reconstruction
Your task
Given a directed multigraph with n nodes (0..n-1) and a list of directed edges (parallel edges allowed), reconstruct an Eulerian circuit: a closed walk that uses every edge exactly once and returns to its start. Return the sequence of visited nodes (length = #edges + 1); if no Eulerian circuit exists return an empty list. To make the output deterministic, when leaving a node always take the unused outgoing edge to the smallest-numbered neighbor first. For an empty edge list return []. Assume 1 <= n <= 2000.
Examples
eulerian_circuit(n: int, edges: list[list[int]]) -> list[int]Example 1
Input
eulerian_circuit(3, [[0, 1], [1, 2], [2, 0]])Output
[0, 1, 2, 0]