(defconstant +inf+ 9876543218987654321) (defun main (&rest argv) (declare (ignorable argv)) (let* ((n (read)) (s (make-array n :element-type 'integer))) (dotimes (i n) (setf (aref s i) (read))) (let* ((m (read)) (d (make-array (list n n) :element-type 'integer :initial-element +inf+)) (res +inf+)) (dotimes (i n) (setf (aref d i i) 0)) (dotimes (i m) (let* ((a (read)) (b (read)) (c (read))) (setf (aref d a b) c (aref d b a) c))) (dotimes (i n) (dotimes (j n) (dotimes (k n) (setf (aref d j k) (min (aref d j k) (+ (aref d j i) (aref d i k))))))) (loop for i from 1 below (1- n) do (loop for j from 1 below (1- n) do (unless (= i j) (setq res (min res (+ (aref d 0 i) (aref s i) (aref d i j) (aref s j) (aref d j (1- n)))))))) (format t "~d~%" res)))) (main)