A directed graph G has N vertices and N(N−1)/2 edges. The vertices are numbered from 0 to N−1. For any two different vertices i and j, exactly one of the edge from i to j and the edge from j to i is present. Ignoring the directions, G is a complete graph.
X is the adjacency matrix of G. When Xi,j is +, the edge from i to j exists, and when it is -, that edge does not exist. Xi,i is always ..
A Hamiltonian path of G is a path of length N that visits every vertex exactly once. G can have many Hamiltonian paths, so find the one whose sequence of visited vertex numbers comes first in lexicographic order. Sequence a comes before sequence b when a holds the smaller value at the first position where the two sequences differ.