You have been assigned a task to write a program which takes a multigraph as its input and if it contains an Eularian circuit to return one. Otherwise, the program's behavior is undefined, according to the specifications you're handed by your boss.
However, you recently caught your new coworker Steven several times treating undefined behavior in C carelessly and urged him be more careful because undefined behavior can also mean that all files on the system get deleted. He now dared you to write your program in a way such that it deletes itself when the aforementioned case of (previously) undefined behavior occurs. You don't want to lose your honor and accept.
An Eulerian circuit is a circuit in an undirected multigraph which visits every edge exactly once.
You may choose the formats of your program's input and output yourself. They don't need to be the same formats. For example, you may take a description of the edges like
as your input for this graph
, but return a sequence of vertices as your output:
You don't need to be able to accept multigraphs which contain vertices without edges.
Holding your program only in RAM and terminating it afterwards doesn't count as deleting it. It needs to be in a file. The file must only be deleted if no Eulerian circuit exists in the input multigraph.
The vertices have to be identifiable (it needs to be possible to tell the Euler circuit in the input provided the output of your program), the edges don't. However, you may restrict the means of identification (e.g. only positive integers or only strings consisting of a
# followed by a positive integer) as long as large graphs are representable (only 1 letter of the English alphabet isn't sufficient). Identifiers don't have to be explicit. For example, you may let the order of the input determine the number a vertex is identified with in the output.
The means of output (saved to a file, printed at stdout, return value of a function) don't matter.
You can't rely on the name of your program on the disk not changing. If you only write a function, you still have to delete the file on the disk.
This is code golf, shortest code wins.
Spoiler warning for this link: Simple algorithms to solve this problem can be found on the internet.