To give a matrix, there are some balloons of different colors. Each time you can destroy one row or one color balloon in a column, ask if you are within K times, which of the following colors cannot be used to remove balloons.
The idea is to find the minimum point of coverage for each color balloon, and> K is the answer.
It is equivalent to the enhanced version of poj3041, because not every vertex in the matrix is equivalent.
# Include <cstdio> # include <cstring> # include <cmath> # include <iostream> # include <algorithm> # include <vector> # include <queue> # include <map> const int maxn = 105; using namespace STD; int MX [maxn], my [maxn], vis [maxn], E [maxn] [maxn], n, CNT, MP [maxn] [maxn], mat [maxn], ANS [maxn]; Map <int, int> MMP; int path (int I) {Int J; For (j = 0; j <N; j ++) {If (E [I] [J] &! Vis [J]) {vis [J] = 1; if (my [J] =-1 | path (my [J]) {MX [I] = J; my [J] = I; return 1 ;}}return 0 ;}int hungry () {int res = 0; memset (MX, -1, sizeof MX); memset (My,-1, sizeof my); For (INT I = 0; I <n; I ++) {If (MX [I] =-1) {memset (VIS, 0, sizeof vis); Res + = path (I) ;}} return res ;} int main () {int K, I, j, M, P, X; while (scanf ("% d", & N, & K) & (N | K) {CNT = 1; MMP. clear (); for (I = 0; I <n; I ++) for (j = 0; j <n; j ++) {scanf ("% d ", & amp; MP [I] [J]); If (MMP [MP [I] [J]) continue; else {MMP [MP [I] [J] = CNT; mat [CNT ++] = MP [I] [J] ;}} m = 0; For (P = 1; P <CNT; P ++) {x = mat [p]; memset (E, 0, sizeof E); for (I = 0; I <n; I ++) for (j = 0; j <n; j ++) if (MP [I] [J] = x) E [I] [J] = 1; if (hungry ()> K) ans [M ++] = x;} If (M = 0) printf ("-1 \ n"); else {sort (ANS, ANS + M ); // wa once .. Printf ("% d", ANS [0]); for (I = 1; I <m; I ++) printf ("% d", ANS [I]); puts ("") ;}} return 0 ;}