/*
There are 1-50 balloons in the matrix with n * n, and only one row or column can be destroyed at a time. K. After this operation, the balloons cannot be destroyed.
Solution: For each given color, when map [I] [j] = color, we can consider that there is an I-j path, so that we can build a bipartite graph, the two points in the bipartite graph are the horizontal and vertical coordinates of the color balloon, and the number of times required to destroy all the balloons of the colo r is the minimum point coverage of the Bipartite Graph.
What is vertex coverage
*/
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Define M 105
# Define N 55
Int map [M] [M], link [M], flag [M], ans [N], n, k; // note: the length of the link and flag arrays should be equal to the number of columns in the matrix;
Int find (int I, int color)
{
Int j;
For (j = 1; j <= n; j ++ ){
If (map [I] [j] = color & flag [j] = 0 ){
Flag [j] = 1;
If (link [j] = 0 | find (link [j], color) = 1 ){
Link [j] = I;
Return 1;
}
}
}
Return 0;
}
Int getnum (int color)
{
Int I, sum;
Memset (link, 0, sizeof (link ));
For (I = 1, sum = 0; I <= n; I ++ ){
Memset (flag, 0, sizeof (flag ));
If (find (I, color) = 1)
Sum ++;
}
Return sum;
}
Int main ()
{
Int I, j, t;
While (scanf ("% d", & n, & k), n | k ){
Memset (map, 0, sizeof (map ));
Memset (ans, 0, sizeof (ans ));
For (I = 1; I <= n; I ++ ){
For (j = 1; j <= n; j ++ ){
Scanf ("% d", & map [I] [j]);
}
}
For (I = 1, t = 0; I <= 50; I ++) {// note that each color is traversed here, so the number of cycles equals to the number of all colors
If (getnum (I)> k)
Ans [t ++] = I;
}
If (t = 0)
Printf ("-1 \ n ");
Else {
For (I = 0; I <t; I ++ ){
Printf (I = 0? "% D": "% d", ans [I]);
}
Printf ("\ n ");
}
}
Return 0;
}
# Include <stdio. h>
# Include <string. h>
# Define M 105
# Define N 55
Int map [M] [M], link [M], flag [M], ans [N], n, k; // note: the length of the link and flag arrays should be equal to the number of columns in the matrix;
Int find (int I, int color)
{
Int j;
For (j = 1; j <= n; j ++ ){
If (map [I] [j] = color & flag [j] = 0 ){
Flag [j] = 1;
If (link [j] = 0 | find (link [j], color) = 1 ){
Link [j] = I;
Return 1;
}
}
}
Return 0;
}
Int getnum (int color)
{
Int I, sum;
Memset (link, 0, sizeof (link ));
For (I = 1, sum = 0; I <= n; I ++ ){
Memset (flag, 0, sizeof (flag ));
If (find (I, color) = 1)
Sum ++;
}
Return sum;
}
Int main ()
{
Int I, j, t;
While (scanf ("% d", & n, & k), n | k ){
Memset (map, 0, sizeof (map ));
Memset (ans, 0, sizeof (ans ));
For (I = 1; I <= n; I ++ ){
For (j = 1; j <= n; j ++ ){
Scanf ("% d", & map [I] [j]);
}
}
For (I = 1, t = 0; I <= 50; I ++) {// note that each color is traversed here, so the number of cycles equals to the number of all colors
If (getnum (I)> k)
Ans [t ++] = I;
}
If (t = 0)
Printf ("-1 \ n ");
Else {
For (I = 0; I <t; I ++ ){
Printf (I = 0? "% D": "% d", ans [I]);
}
Printf ("\ n ");
}
}
Return 0;
}