module Exercise_5 where import Test.QuickCheck import Data.List {- H5.3 -} {-WETT-} type Vertex = Int type Edge = (Vertex, Vertex) type Graph = ([Vertex], [Edge]) longestPath :: Graph -> Vertex -> Int longestPath (vs,es) t = let ts = topsort [(v,0) | v<- vs] es in head [c | (t',c) <- ts, t' == t] topsort :: [(Vertex,Int)] -> [Edge] -> [(Vertex,Int)] topsort [] es = [] topsort ((s,c):vs) es = (s,c) : topsort [(s, if elem (s,t) es then maximum (1 + c, c') else c') | (t,c') <- vs] es {-TTEW-}