50 years, 50 colors
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1507 accepted submission (s): 811
Problem descriptionon octorber 21st, HDU 50-Year-celebration, 50-color balloons floating around the campus, it's so nice, isn' t it? To celebrate this meaningful day, the ACM team of HDU hold some fuuny games. Especially, there will be a game named "crashing color balloons ".
There will be a n * n matrix board on the ground, and each grid will have a color balloon in it. and the color of the Ballon will be in the range of [1, 50]. after the referee shouts "Go! ", You can begin to crash the balloons. every time you can only choose one kind of balloon to crash, we define that the two balloons with the same color belong to the same kind. what's more, each time you can only choose a single row or column of balloon, and crash the balloons that with the color you had chosen. of course, a lot of students are waiting to play this game, so we just give every student K times to crash the balloons.
Here comes the problem: Which kind of balloon is impossible to be all crashed by a student in K times.
Inputthere will be multiple input cases. each test case begins with two integers n, k. n is the number of rows and columns of the balloons (1 <= n <= 100), and K is the times that ginving to each student (0 <k <= N ). follow a matrix A of N * n, where AIJ denote the color of the ballon in the I row, J column. input ends with N = k = 0.
Outputfor each test case, print in ascending order all the colors of which are impossible to be crashed by a student in K times. If there is no choice, print "-1 ".
Sample Input
1 112 11 11 22 11 22 25 41 2 3 4 52 3 4 5 13 4 5 1 24 5 1 2 35 1 2 3 43 350 50 5050 50 5050 50 500 0
Sample output
-1121 2 3 4 5-1
A matrix of N * n. Each lattice contains a balloon with color. One person can select a balloon of a color at a time, and then select a row or column to break the balloon of this color;
You have k chances to see if all the balloons of a certain color are broken. If some colored balloons cannot be broken, output the balloons in the ascending order. Otherwise, output-1.
Find the least vertex in the bipartite graph and associate each edge with at least one vertex. This is the "minimum vertex overwrite" of the Bipartite Graph ".
The minimum vertex overwrites of a bipartite graph = the maximum number of Matching Parts of a bipartite graph.
# Include "stdio. H "# include" string. H "# define n 105int G [N] [N], vis [N]; int mark [N], link [N], n; int find (INT t, int K) {int I; for (I = 1; I <= N; I ++) {If (G [k] [I] = T &&! Mark [I]) {mark [I] = 1; if (link [I] =-1 | find (T, link [I]) {link [I] = K; return 1 ;}} return 0 ;}int getsum (INT t) {int I, CNT = 0; memset (link,-1, sizeof (Link); for (I = 1; I <= N; I ++) {memset (mark, 0, sizeof (Mark )); CNT + = find (t, I);} return CNT;} int main () {int K, I, j, T; while (scanf ("% d ", & N, & K), N | K) {memset (G, 0, sizeof (g); memset (VIS, 0, sizeof (VIS )); for (I = 1; I <= N; I ++) {for (j = 1; j <= N; j ++) {scanf ("% d ", & T); G [I] [J] = T; If (! Vis [T]) // a certain color balloon appears vis [T] = 1 ;}} int ans [N], CNT = 0, S1; for (I = 1; I <= 50; I ++) // balloon of 50 colors {If (vis [I]) {S1 = getsum (I); If (S1> K) // if the number of matches is greater than K, the balloon cannot be completely broken. ans [CNT ++] = I;} If (CNT = 0) printf ("-1 \ n"); else {for (I = 0; I <cnt-1; I ++) printf ("% d", ANS [I]); printf ("% d \ n", ANS [cnt-1]) ;}} return 0 ;}