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 several cases, each one with 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 .
For every case, print the cost of the worst path without repeated vertices that begins at .
Author: Salvador Roura
Generation: 2026-01-25T09:54:43.549Z
© Jutge.org, 2006–2026.
https://jutge.org