// Souffle - A Datalog Compiler
// Copyright (c) 2017, 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

// Finds the length of the path that visits the most nodes without overlapping itself

.type node <: symbol

.decl edge(x : node, y : node)
.input edge()

// Find all paths between all nodes
.decl length(x : node, y : node, l : number)
length(x,y,l) :- l = 2, edge(x, y).
length(x,y,l+1) :- edge(x, z), length(z, y, l).

// Find the start and end of the path with the most nodes visited
.decl longest_path(x : node, y : node, l : number)
.output longest_path()
longest_path(y, x, l) :- l = max m : length(x, y, m).
