// Souffle - A Datalog Compiler
// Copyright (c) 2016, The Souffle Developers. All rights reserved
// Licensed under the Universal Permissive License v 1.0 as shown at:
// - https://opensource.org/licenses/UPL
// - <souffle root>/licenses/SOUFFLE-UPL.txt

// Type Node
.type Node <: symbol

//
// Edges non circular
//

.decl Edge        (n:Node, m:Node, w:number)

Edge("0","1",3).
Edge("1","2",5).
Edge("2","3",1).
Edge("1","4",-6).
Edge("4","2",-1).

//
// Reachable
//

.decl Reachable   (n:Node, m:Node, i:number)
.output Reachable   ()

Reachable(x,y,r)  :- r=w, Edge(x,y,w).
Reachable(x,y,d+w)  :- Edge(x,z,w), Reachable(z,y,d).


.decl ShortestDuplicates(n:Node, m:Node, i:number)
.output ShortestDuplicates()

ShortestDuplicates(x,y,a) :- Reachable(x,y,a), Reachable(x,y,b), a<b.
