g(a,b). g(a,d). g(b,c). g(d,e). g(e,b). g(c,f). path(X,Y):-g(X,Y). path(X,Y):-g(X,Z), path(Z,Y).