Given a directed and complete graph with vertices, and an initial vertex , compute the maximum cost of all the paths without repeated vertices that begin at . The given graph is represented by an matrix , where for every pair with , is the (perhaps negative) cost of the arc from to .
For instance, the maximum cost of the first test is 80, corresponding to the path , with cost .
Input consists of the number of vertices , followed by the matrix ( lines, each one with integer numbers), followed by the initial vertex . Vertices are numbered from 0 to . You can assume , , that the diagonal has only zeros, and that the rest of numbers are between and .
Print the maximum cost of all the paths without repeated vertices that begin at .
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T11:22:32.339Z
© Jutge.org, 2006–2026.
https://jutge.org