View source with raw comments or as raw
    1% fact for each vertex(N).
    2vertex(0).
    3vertex(1).
    4vertex(2).
    5vertex(3).
    6
    7% fact for each edge edge(U, V).
    8edge(0, 1).
    9edge(1, 2).
   10edge(2, 3).
   11edge(3, 0).
   12
   13edge(2, 0).
   14edge(0, 3).
   15edge(3, 1).
   16
   17reachable(V) :- chosen(U, V), reachable(U).
   18reachable(0) :- chosen(V, 0).
   19
   20% Every vertex must be reachable.
   21:- vertex(U), not reachable(U).
   22
   23% Choose exactly one edge from each vertex.
   24other(U, V) :-
   25    vertex(U), vertex(V), vertex(W),
   26    edge(U, W), V \= W, chosen(U, W).
   27chosen(U, V) :-
   28    edge(U, V), not other(U, V).
   29
   30% You cannot choose two edges to the same vertex
   31:- chosen(U, W), chosen(V, W), U \= V.   32?- chosen(1,2).