[Solution] Cross Swapping Codeforces Solution
You are given a square matrix of size whose elements are integers. We will denote the element on the intersection of the -th row and the -th column as .
You can perform operations on the matrix. In each operation, you can choose an integer , then for each index (), swap with . Note that cell remains unchanged.
For example, for and , this matrix will be transformed like this:
The operation swaps the blue row with the green column.You can perform this operation any number of times. Find the lexicographically smallest matrix you can obtain after performing arbitrary number of operations.
occupied
For two matrices and of size , let and . Then, the matrix is lexicographically smaller than the matrix when there exists an index () such that and for all indices such that , .
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the size of the matrix.
The -th line of the next lines contains integers () — description of the matrix .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print lines with integers each — the lexicographically smallest matrix.
No comments:
Post a Comment