r(g,h). 
r(g,d).
r(e,d).
r(h,f).
r(e,f).
r(a,e).
r(a,b).
r(b,f).
r(b,c).
r(f,c).

path(X,Y):- r(X,Y).
path(X,Y):- r(X,Z),path(Z,Y).

pathn0(X,Y,s(0)):- r(X,Y).
pathn0(X,Y,s(M)):- r(X,Z), pathn0(Z,Y,M).

pathn(X,Y,1):- r(X,Y).
pathn(X,Y,N):- r(X,Z),pathn(Z,Y,M), N is M+1.
