Link: poj 1466
There are n students, each of which has a relationship with some people. Now you need to find the maximum number of students so that they do not matter.
Idea: Find the maximum independent set, the maximum independent set = points-the maximum number of matches
Analysis: when creating a picture, it should be a boy's point while a girl's point. But the question does not mention gender, and each point can only be split into two points, one is treated as a male point, the other is a female point, and then the edge is connected. because the relationship is mutual, edge duplication occurs. That is to say, the edge set is twice as long as the current one, resulting in the largest matching to double the original. Therefore, the maximum independent set = point-Maximum number of matching/2.
# Include <stdio. h> # include <string. h> int N, edge [510] [510], link [510], used [510]; int DFS (int pos) {int I; for (I = 0; I <n; I ++) {If (edge [POS] [I] &! Used [I]) {used [I] = 1; if (link [I] =-1 | DFS (link [I]) {link [I] = Pos; return 1 ;}} return 0 ;}int main () {int I, j, A, B, S, M; while (scanf ("% d", & N )! = EOF) {memset (edge, 0, sizeof (edge); for (I = 0; I <n; I ++) {scanf ("% d: (% d) ", & A, & M); For (j = 0; j <m; j ++) {scanf (" % d ", & B ); edge [a] [B] = 1; // graph} memset (link,-1, sizeof (Link); s = 0; for (I = 0; I <n; I ++) {memset (used, 0, sizeof (used); S + = DFS (I);} printf ("% d \ n ", n-S/2); // remember to subtract half of the maximum number of matches} return 0 ;}
Poj 1466 girls and boys (Maximum Independent Set)