acmsguru |
---|
Finished |
122. The book time limit per test: 0.25 sec.
There is a group of N (2<=N<=1000) people which are numbered 1 through N, and everyone of them has not less than [ (N+1) / 2 ] friends. A man with number 1 has the book, which others want to read. Write the program which finds a way of transferring the book so that it will visit every man only once, passing from the friend to the friend, and, at last, has come back to the owner. Note: if A is a friend of B then B is a friend of A.
Input First line of input contains number N. Next N lines contain information about friendships. (i+1)-th line of input contains a list of friends of i-th man.
Output If there is no solution then your program must output 'No solution'. Else your program must output exactly N+1 number: this sequence should begin and should come to end by number 1, any two neighbours in it should be friends, and any two elements in it, except for the first and last, should not repeat.
Sample Input 4 2 3 1 4 1 4 2 3
Sample Output 1 3 4 2 1 |
Name |
---|