Lexicographically smallest tournament ranking
Your task
A tournament is a directed graph on n players (0..n-1) where, for every unordered pair {i, j}, exactly one directed edge exists; matches is the list of those edges, where [u, v] means u beat v. A full ranking is an ordering of all players where each player beat the next one in the ordering (a Hamiltonian path along the beat edges) -- one always exists in a tournament. Return the lexicographically smallest such ordering as a list of player ids. Constraints: 2 <= n <= 20.
Examples
lex_ranking(n: int, matches: list[list[int]]) -> list[int]Example 1
Input
lex_ranking(3, [[0, 1], [1, 2], [2, 0]])Output
[0, 1, 2]