Directed Eulerian path reconstruction
Your task
Given a directed graph with n nodes (0..n-1) and directed edges [u, v], reconstruct an Eulerian path: a walk using every directed edge exactly once. If one exists, return the list of node labels visited in order (length = number_of_edges + 1); the path must begin at the unique vertex with out-degree minus in-degree equal to 1 when such a vertex exists, otherwise at the lowest-numbered vertex that has an outgoing edge. Within each vertex, leave via edges in the input order. If no Eulerian path exists, return []. Constraints: 1 <= n <= 1000.
Examples
eulerian_path_directed(n: int, edges: list[list[int]]) -> list[int]Example 1
Input
eulerian_path_directed(3, [[0, 1], [1, 2]])Output
[0, 1, 2]