F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Little prince and the garden of roses

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 44    Accepted Submission(s): 16
Special Judge


Problem Description
He was standing before a garden, all a-bloom with roses.
"Good morning," said the roses.
The little prince gazed at them. They all looked like his flower.
"Who are you?" he demanded, thunderstruck.
"We are roses," the roses said.
And he was overcome with sadness. His flower had told him that she was the only one of her kind in all the universe. And here were five thousand of them, all alike, in one single garden!
"She would be very much annoyed," he said to himself, "if she should see that... she would cough most dreadfully, and she would pretend that she was dying, to avoid being laughed at. And I should be obliged to pretend that I was nursing her back to life-- for if I did not do that, to humble myself also, she would really allow herself to die..."
Then he went on with his reflections: "I thought that I was rich, with a flower that was unique in all the world; and all I had was a common rose. A common rose, and three volcanoes that come up to my knees-- and one of them perhaps extinct forever... that doesn't make me a very great prince..."
And he lay down in the grass and cried.


Assume the garden of roses has $n$ rows of roses, where there are $n$ roses in each row, aligned in a square. Initially, each rose has a color(color of the petals, of course!). The rose in the $i$-th row and $j$-th column is colored with $c_{ij}$.(There are surely colorful roses! Why would people only think of red ones when it comes to roses?)

When little prince wanders in the garden of roses, he will burst into tears when he sees two roses with the same color in the same row or the same column, as that would remind him his flower is not unique in this world.

You, a kind person, definitely don't want to see the little prince cry. Fortunately, you arrived at the garden of roses just before the little prince. You have a magic painter that could paint the stems of some roses into different colors(You don't want to ruin the petals of the roses, do you?). Initially, the stems of all roses are green. You want to paint the stems of some roses into different colors, such that no two roses in the same row or column would no longer have both the same color of petals and stems. The only problem is the number of pigments with distinct colors you need to prepare. As preparing pigments with distinct colors is time-consuming, you want to use as little pigments as possible. Please find a way to paint the flowers such that the condition is satisfied. As long as the number of pigments is minimized, any valid way of painting flowers would be considered correct.
 

Input
The first line contains a number $T(1\leq T\leq 100)$, denoting the number of test cases.
The first line of each test case contains an integer $n(1\leq n\leq 300)$, denoting the size of the garden.
Then $n$ lines follow, the $i$th$(1\leq i\leq n$) of the $n$ lines contain $n$ integers $c_{i1},c_{i2},\dots,c_{in}$, where $c_{ij}(1\leq i,j\leq n,1\leq c_{ij}\leq n^2)$ denotes the color of the rose in the $i$th row and $j$th column.

It is guaranteed that at most $10$ cases $n>20$ and at most $4$ cases $n>100$.
 

Output
For each test case, output two integers $d,m(0\leq d\leq n^2,1\leq m\leq n^2)$ in the first line, denoting the number of distinct pigments used and the number of roses to be painted.
For the next $m$ lines, output three integers $i,j,c(1\leq i,j\leq n,1\leq c\leq d)$ in a line, denoting that you would paint the stem of the rose in the $i$th row and $j$th column into color $c$. If the stem of some rose is not painted, it is regarded to have color 0.
As long as the number of pigments is minimized, any valid way of painting the stems of the roses would be considered correct.
 

Sample Input
3 3 1 1 1 1 1 1 1 1 1 3 1 2 1 2 1 2 1 2 1 3 1 2 3 4 5 6 7 8 9
 

Sample Output
2 6 1 2 2 1 3 1 2 1 1 2 3 2 3 1 2 3 2 1 1 4 1 3 1 3 1 1 2 3 1 3 2 1 0 0
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 22:32:38, Gzip enabled