Restore the permutation
InterviewTime limit2sMemory limit1024 MB
Given an N by N comparison matrix, restore a permutation that produces it, or print -1 if no permutation matches.
- Level
Easy3 of 10
- Topics
- Matrix, Sorting, Implementation
- Solved
- No attempts yet
Problem
A permutation of length is a sequence in which each integer from to appears exactly once. For example, and are permutations, but and are not.
For a permutation of length , the comparison matrix is an matrix. Each element is set as follows, based on how compares with .
- If , then .
- If , then .
- If , then .
Given the comparison matrix , write a program that restores the permutation . If no permutation satisfies , print -1.
Input
The first line contains an integer . ()
Each of the next lines contains a row of the comparison matrix . The -th line holds , separated by spaces. Every element of the matrix is , , or .
Output
If a permutation satisfies the comparison matrix , print separated by spaces, in order. If several permutations work, print any of them.
If no such permutation exists, print -1.