type
T: array [1..n] of integer;
var
graph: [1..n, 1..n] of integer; // матрица смежности
visited: array [1..n] of boolean;
{ возвращает true если контуров нет *}
function check_for_circuits(start_node: integer; current_node: integer; step: integer): boolean;
var
stack: T;
k: integer;
i: integer;
res: boolean;
begin
if (step > 1) and (start_node == current_node) then
Exit(false);
res := true;
for i := 1 to n do
// короче, первое условие - это проверка на смежность
if (graph[current_node, i] <> 0) and not visited[i] then
if not check_for_circuits(start_node, i, step + 1) then
Exit(false);
Exit(true);
end;
// ...
res := true;
for i := 1 to n do
if res then
begin
for j := 1 to n do
visited[j] := false;
if res then // чтоб не перезаписалось в случае, если res уже равно false
res := check_for_circuits(i, i, 1);
end;