2vertex(a).
3vertex(b).
4vertex(c).
5vertex(d).
6
7
9edge(b, a).
10edge(b, d).
11edge(a, c).
12
13edge(a, b).
14edge(b, c).
15edge(c, d).
16edge(d, a).
17
18edge(c, a).
19edge(a, d).
20edge(d, b).
21
22
23reachable(V) :- chosen(V, a).
24reachable(V) :- chosen(V, U), reachable(U).
25
26
27% Choose exactly one edge from each vertex.
28chosen(U, V) :-
29 edge(U, V), not other(U, V).
30other(U, V) :-
31 edge(U, V), not chosen(U, V).
32
33% Every vertex must be reachable.
34:- vertex(U), not reachable(U).
36:- chosen(U, W), U \= V, chosen(V, W). 37:- chosen(W, U), U \= V, chosen(W, V). 38
39?- reachable(a). 40
41#