[Home|Training|Problems|Contests|C Language] | [Login|Register] |
Problems Status Rank Statistics |
Problem F
Find the Simple Circle
Time Limit: 1000ms
Memory Limit: 65536kb Description
Given a directed graph, your task is to find the simple circles. The simple circle is a subgraph meeting the following conditions:1. There are m ( m > 1 ) different vertexes and arcs in it. 2. The simple circle can be represented as a seqence "v1,v2...vm" and v1,v2...vm are different vertexes in it. There is an arc from the i-th vertex to the (i+1)-th vertex or from the m-th vertex to the 1st vertex in the simple circle. You will be given the adjacency matrix of the directed graph, what you should do is outputing all the simple circles in it in lexicographic order. The output format of one simple circle is a string where the i-th character is the index of the i-th vertex in the simple circle seqence. To unify the format, the 1st vertex should be the vertex with smallest index. Vertexes are indexed from 0. A sequence a1,a2...ak appears in lexicographic order before a sequence b1,b2...bk if and only if the first ai, which is different from bi, is less than bi. Input
There are several test cases in the input. Each case begins with a line with an integer N (2 ≤ N ≤ 9), denoting the number of vertexes in the graph. In the following N lines with N integers, the j-th number in the i-th line will be 1 or 0, representing that there is an arc from the i-th vertex to the j-th vertex or not. It is ensured that the i-th number in the i-th line is 0. Input is terminated by EOF.
Output
Output one simple circle sequence in one line, and end each case with a blank line.
Sample Input
3 0 1 1 1 0 1 1 1 0 4 0 1 0 1 1 0 1 0 1 0 0 1 1 0 1 0 Sample Output
01 012 02 021 12 01 012 0123 03 032 23 Source
HIT
|