Under construction

Still being built. Things may change

KUBC League (Small)

Time limit1sMemory limit256 MB

Summary
Given a tournament on N players, find the longest simple path starting at player 1 and output the lexicographically smallest such path.
Level

Medium6 of 10

Topics
Graph, DFS, Backtracking, Brute force
Solved
No attempts yet

Problem

KUBC, the badminton club of Korea University, ran a league for its full members. NN players including Taeyang entered, every pair played exactly once, so the league had N(N−1)/2N(N-1)/2 matches. No match ended in a draw, so the results produced a standings table.

Standings table

Hyunsu looked at the table and screamed. 'I am tied for last? Last place... no, me, in last place! What is this! Aaaargh.' Then he started to rationalize. 'I beat Hanyong, Hanyong beat Sechan, Sechan beat Chanwoo, and Chanwoo beat Taeyang. So I beat everyone else after all!'

Taeyang is tied for last as well and wants to argue the same way, but he cannot find a way to beat the other 4 players. Help Taeyang and write a program that builds a chain of players, where each player in the chain beat the next one.

Input

The first line contains NN. (2≤N≤202 \le N \le 20)

Each of the next NN lines contains NN integers. The qq-th number on line p+1p+1 follows the rules below.

  • It is 1 if player pp beat player qq.
  • It is 0 if player pp lost to player qq.
  • It is 0 if p=qp = q.

For two different players pp and qq, exactly one of the two numbers is 1. Taeyang is player 1.

Output

On the first line, print the maximum length LL of the chain.

On the second line, print the chain S1 S2 … SLS_1\ S_2\ \dots\ S_L separated by spaces. The chain must satisfy every condition below.

  • S1=1S_1 = 1.
  • S1,S2,…,SLS_1, S_2, \dots, S_L are pairwise different.
  • For every ii with 1≤i≤L−11 \le i \le L-1, player SiS_i beat player Si+1S_{i+1}. Player SLS_L does not have to beat player S1S_1.

If several chains have length LL, print the lexicographically smallest one, comparing the numbers from the front.

Examples2

  1. Example 1

    Input
    5
    0 0 0 1 0
    1 0 0 1 1
    1 1 0 1 0
    0 0 0 0 1
    1 0 1 0 0
    
    Expected output
    5
    1 4 5 3 2
    
  2. Example 2

    Input
    5
    0 0 0 0 0
    1 0 0 0 0
    1 1 0 0 0
    1 1 1 0 0
    1 1 1 1 0
    
    Expected output
    1
    1