Дано: граф заданный матрицей смежности.
(defun iel(spis i)
((ZEROP i)(car spis))
(iel (CDR spis)(- i 1))
)
(DEFUN CHANGE (lst nn val)
((ZEROP nn) (POP lst) (PUSH val lst))
(CONS (CAR lst) (CHANGE (CDR lst) (- nn 1) val))
)
(defun matr(m i j)
(SET 'q (IEL m i))
(SET 'q (IEL q j))
RETURN q
)
(defun changematr(m i j val)
(SET 'q(IEL m i))
(SET 'q (CHANGE q j val))
(CHANGE m i q)
)
(defun gamilt(v p)
(SET 'n1 (- n 1))
(SET 'c (iel cycle n1))
((AND(EQL cnt n)(EQL (matr a c 0) 1))(PRINT cycle)(RETURN))
((EQL p n )(RETURN))
((AND(EQL 1 (matr a v p))(EQL 0 (iel used p)))
(SET 'used (CHANGE used p 1))
(SET 'a (changematr a v p 0))
(SET 'a (changematr a p v 0))
(SET 'cycle (change cycle cnt p))
(SET 'cnt (ADD1 cnt))
(gamilt p 0)
(SET 'cnt (- cnt 1))
(SET 'used (CHANGE used p 0))
(SET 'a (changematr a v p 1))
(SET 'a (changematr a p v 1))
(gamilt v (+ p 1))
)
(gamilt v (+ p 1))
)
(SET 'stack NIL)
(SET 'n 6)
(SET 'a '((0 1 0 0 0 1)
(1 0 0 0 1 1)
(0 0 0 1 1 1)
(0 0 1 0 1 0)
(0 1 1 1 0 0)
(1 1 1 0 0 0)))
(SET 'cycle '(0 0 0 0 0 0))
(SET 'used '(0 0 0 0 0 0))
(SET 'cnt 0)
(SET 'cycle (CHANGE cycle cnt 0))
(SET 'cnt (ADD1 cnt))
(SET 'used (CHANGE used 0 1))
(gamilt 0 0)
|