F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Find The Simple Circle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 563    Accepted Submission(s): 290


Problem 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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 21:27:27, Gzip enabled