parent(a,b).
parent(a,c).
parent(c,e).
parent(c,d).
parent(b,f).
parent(f,g).

ancestor(A,X) :- parent(A, X).
ancestor(A,X) :- parent(P, X), ancestor(A,P).

ans_swapped(A,X) :- parent(A, X).
ans_swapped(A,X) :- ancestor(A,P), ans_swapped(A,P).


