標準 ML で SCC アルゴリズムを記述する必要があります。しかし、方法がわかりません。
コードで使用する必要がある次のタイプがあります。
type vertex = int
type edge = int * int
type graph = (vertex * vertex list) list
fun dfs (g: graph) (n: vertex): vertex list =
let
fun helper (todo: vertex list) (visited: vertex list): vertex list =
case todo of
[] => []
| h::t => if (List.exists (fn x => x = h) visited)
then helper t visited
else
let
val adj = case List.find (fn (n, _) => n = h) g of
NONE => raise Fail "incomplete adjacency list"
| SOME (_, adj) => adj
in
h :: (helper (adj @ t) (h::visited))
end
in
helper [n] []
end
上記のコードは正しくコンパイルされ、実行されています。
SCC dfs の計算に必要なことがわかっているので、これらをコードに入れました。
誰にも解決策がありますか?