Book of programming problems

Contains advanced programming problems for schools, colleges and problem-hungry inidividuals

Find the longest path in a graph
Complexity (1-100): 30
A graph with equal edge lengths is given. Find the longest path in that graph such that it does not contain any vertex twice.

The graph is specified by a connectivity matrix M, where Mi,j is 1 if if there is an edge between vertexes i and j, and 0 otherwise. The matrix is symmetric: MT=M. The input file contains the number of vertexes N. The following N lines contain matrix data, N numbers at each row. These are some self-tests:
  1. 13 vertex graph. The longest path: 1 8 7 6 5 2 3 4 9 10 11 13 12
  2. A full graph with 12 vertexes. The longest path is any permutation of vertexes, e.g. 1 2 3 4 5 6 7 8 9 10 11 12
  3. 11 vertex, 15 edges graph.The longest path is 6 7 1 5 2 3 4 8 9 10 11
  4. A full graph with 8 vertexes. The longest path is any permutation of vertexes, e.g. 1 2 3 4 5 6 7 8
Solution:Show/hide explanation | solution.pas
There are no posts in this topic.

Post Reply

Book of programming problems is powered by UseBB 1 Forum Software | Contact Admin