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); if step > 1 then visited[current_node] := true; 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; res := check_for_circuits(i, i, 1); end;