Eulerian paths and circuits · Compiler

Eulerian paths and circuits

Find the smallest vertex ID from which a courier can use every one-way street exactly once in a single walk. The courier may revisit vertices and may finish at the starting vertex. With no streets a walk of length zero can start anywhere.

Input
The first line contains n m. Vertices are numbered 0 through n-1 (1 <= n <= 50, 0 <= m <= 200). Each of the next m lines contains u v for an edge from u to v. Endpoints differ and each ordered pair occurs at most once.
Output
Print the smallest valid starting vertex, or -1 if no such walk exists.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…