Under construction

Still being built. Things may change

Similarity Graph

Time limit1sMemory limit1024 MB

Summary
Given a graph on N vertices, find two permutations p and q whose similarity graph equals it, or report NO if none exists.
Level

Hard8 of 10

Topics
Graph, Topological sort, Implementation
Solved
No attempts yet

Problem

Let pp and qq be two permutations of {1,2,…,N}\{1,2,\dots,N\}.

The similarity graph of pp and qq, S(p,q)S(p,q), is defined as follows:

  • S(p,q)S(p,q) has NN labeled vertices, numbered from 11 to NN.
  • There is an edge between vertex ii and vertex jj if and only if both pi<pjp_i<p_j and qi<qjq_i<q_j are true, or both are false. (1≤i<j≤N1\leq i<j\leq N)

You are given a simple undirected graph GG with NN labeled vertices, numbered from 11 to NN. Find a pair (p,q)(p,q) of permutations of {1,2,…,N}\{1,2,\dots,N\} that satisfies S(p,q)=GS(p,q)=G.

Input

The first line contains one integer NN.

The next NN lines each contain NN space-separated integers. The jj-th integer on the ii-th line is E(i,j)E(i,j). E(i,j)E(i,j) is 11 if there is an edge between vertex ii and vertex jj, and 00 otherwise.

Output

If no pair (p,q)(p,q) satisfies the condition, output NO.

Otherwise, output YES on the first line. On the next two lines, output pp and qq. If there are multiple answers, any of them is accepted.

Constraints

  • 1≤N≤1001\leq N\leq 100
  • 0≤E(i,j)≤10\leq E(i,j)\leq 1 (1≤i,j≤N1\leq i,j\leq N)
  • E(i,j)=E(j,i)E(i,j)=E(j,i) (1≤i<j≤N1\leq i<j\leq N)
  • E(i,i)=0E(i,i)=0 (1≤i≤N1\leq i\leq N)

Examples2

  1. Example 1

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

    Input
    6
    0 1 0 1 0 1
    1 0 0 0 1 0
    0 0 0 1 1 1
    1 0 1 0 0 0
    0 1 1 0 0 0
    1 0 1 0 0 0
    
    Expected output
    NO