:- use_module(library(ordsets), [
			      ord_union/3
				 ]),
    use_module(library(lists), [
			      memberchk/2
				 ]).

warshall(Graph,Closure) :-
    warshall(Graph,Graph,Closure).

warshall([],Closure,Closure).
warshall([V-_|G],E,Closure) :-
    memberchk(V-Y,E), % Y := E(v)
    warshall(E,V,Y,NewE),
    warshall(G,NewE,Closure).

warshall([],_,_,[]).
warshall([X-Neibs|G],V,Y,[X-NewNeibs|NewG]) :-
    memberchk(V,Neibs),
    !,
    ord_union(Neibs,Y,NewNeibs),
    warshall(G,V,Y,NewG).
warshall([X-Neibs|G],V,Y,[X-Neibs|NewG]) :-
       warshall(G,V,Y,NewG).
