/** Base DFS algorithm returns "Yes" or "No". */ program name dfs_yes_no; author "Some clever book :o)"; version 1.0; define DFSNode extends Node attributes string name; boolean visited; ; DFSEdge extends Edge (DFSNode); DFSGraph extends Graph (DFSEdge); var DFSGraph graph; DFSNodes start, finish; function dfs_search (DFSNodes nodes) returns boolean; var DFSNodes friends; DFSNodes friendOne; do if nodes get_intersection_fake(finish) >= 1 then return true; friends := graph get_edges() get_edges_source_is(nodes) get_nodes_destination() get_visited_is(false); for each friendOne from friends do friendOne set_visited(true); if dfs_search(friendOne) then return true; enddo return false; enddo procedure main(); do writeln(get_error_text(graph load_from_file("D:\\Projects\\Rocnikovy projekt\\070419\\graphs\\BGSGraph3.dat"))); start := graph get_nodes() get_name_is("start"); finish := graph get_nodes() get_name_is("end"); if start get_size() != 1 | finish get_size() != 1 then terminate("Chybne urceni zacatku nebo cile hledani!"); if dfs_search(start) then terminate("Existuje alespon jedna cesta ze startu do cile."); terminate("Nebyla nalezana zadna cesta mezi zvolenymi vrcholy!"); enddo