Topic Links:
http://poj.org/problem?id=1466
Main topic:
there are n students, some of whom are ambiguous, only the person who knows can form a collection. Q: you can compose up to
The number of collections makes the students between these collections have nothing to do with.
Ideas:
Select M points from n plots, so that there is no edge between the M points 22, the maximum M is how much. Maximum Independence of the binary chart
Set issues. Should be the boys, girls on each side of the building two-point map to find the largest independent set, but there are only n points, no report
The number of the boys and girls. Then take n students as one side and then n students on the other. Between the people who will connect with each other
Build edges. Then the maximum number of matches is calculated. Because if you and V are connected, both sides (U,V) and (v,u) are added to the two-minute chart,
was repeated calculations for two times. And because the maximum independent set of the binary graph = N-Two The maximum match number of the graph. So the final answer is
N-Maximum number of matches/2.
AC Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std;const int maxn = 550;bool map[maxn][maxn];bool mask[maxn];int nx,ny;int cx[maxn],cy[maxn];int FindPath (int u) {for ( int i = 0; i < NX; ++i) {if (Map[u][i] &&! Mask[i]) {mask[i] = 1; if (cy[i] = =-1 | | Findpath (Cy[i])) {Cy[i] = u; Cx[u] = i; return 1; }}} return 0;} int Maxmatch () {for (int i = 0; i < NX; ++i) cx[i] = 1; for (int i = 0; i < NY; ++i) cy[i] = 1; int res = 0; for (int i = 0, i < NX; ++i) {if (cx[i] = = 1) {for (int j = 0; j < NY; ++j) MASK[J] = 0; Res + = Findpath (i); }} return res;} int main () {int n,k,u,v; while (~SCANF ("%d", &n)) {memset (map,0,sizeof (MAP)); NX = NY = N; for (int i = 0; i < N; ++i) {scanf ("%d: (%d)", &u,&k); for (int j = 0; j < K; ++j) {scanf ("%d", &v); MAP[U][V] = 1; Map[v][u] = 1; }} printf ("%d\n", N-maxmatch ()/2); } return 0;}
POJ1466 Girls and Boys "the maximum independent set of two graphs"