I don't know how to open the zoj website, so I chose a question on hang DIAN to make a picture of the topic. the general meaning of a question is that there are P courses and N students. If each course has a student selection and only one student can select, yes is output; otherwise, no is output. students may have multiple choices, but only one can be selected. A typical Hungarian binary match. If it is a perfect two-point match, the condition is met. note that the student ID starts from 1.
The Code is as follows:
# Include <set>
# Include <map>
# Include <queue>
# Include <stack>
# Include <math. h>
# Include <string>
# Include <vector>
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <limits. h>
# Include <string. h>
# Include <algorithm>
# Include <functional>
Using namespace STD;
Int vis [305] [305];
Int ended [305];
Int match [305];
Int find (int I, int N ){
For (Int J = 1; j <= N; j ++ ){
If (vis [I] [J] &! Ended [J]) {
Ended [J] = 1;
If (Match [J] =-1 | find (Match [J], n )){
Match [J] = I;
Return 1;
}
}
}
Return 0;
}
Int main (){
Int T;
While (scanf ("% d", & T )! = EOF ){
While (t --){
Memset (VIS, 0, sizeof (VIS ));
Memset (match,-1, sizeof (MATCH ));
Memset (ended, 0, sizeof (ended ));
Int P, N, sum = 0, ID;
Scanf ("% d", & P, & N );
For (INT I = 0; I <p; I ++ ){
Scanf ("% d", & sum );
For (Int J = 0; j <sum; j ++ ){
Scanf ("% d", & ID );
Vis [I] [ID] = 1;
}
}
Int res = 0;
For (INT I = 0; I <p; I ++ ){
Memset (ended, 0, sizeof (ended ));
If (find (I, n ))
Res ++;
}
If (RES = P)
Printf ("Yes \ n ");
Else
Printf ("NO \ n ");
}
}
Return 0;
}
Hoj1083 Problem Solving report