Question:
Some students are friends (links cannot be transferred )... now we want to divide a bunch of students into two groups so that there is no friend between the students in the same group .. if it succeeds .. ask me to lock every friend in the dark room .. maximum number of Pairs
Question:
This question reflects the basic conditions of the Bipartite Graph Model... there are two parts .. there is no edge inside. the side is only between two parts... first ask .. is to judge the bipartite graph .. just use the dyeing method .. the next question is the naked Hungary...
Program:
# Include <iostream> # include <stdio. h> # include <algorithm> # include <cmath> # include <stack> # include <string. h >#include <queue> # define ll long # define ESP 1e-5 # define maxn 202 # define maxm 50000000 # define oo 100000007 using namespace STD; int color [maxn], match [maxn]; bool used [maxn]; vector <int> T [maxn]; bool putcolor (int x, int TP) {If (color [x] = 1-tp) return false; If (color [x] = TP) return true; color [x] = TP; For (INT I = 0; I <t [X]. Size (); I ++) if (! Putcolor (T [x] [I],! TP) return false; return true;} bool judge (int n) {memset (color,-1, sizeof (color); For (INT I = 1; I <= N; I ++) if (color [I] =-1 &&! Putcolor (I, 0) return false; return true;} bool DFS (int x) {for (INT I = 0; I <t [X]. size (); I ++) {int y = T [x] [I]; If (used [y]) continue; used [y] = true; If (! Match [y] | DFS (Match [y]) {match [y] = x; return true ;}return false ;} int getmax (int n) {int sum = 0; memset (match, 0, sizeof (MATCH); For (INT I = 1; I <= N; I ++) if (color [I] = 1) {memset (used, false, sizeof (used); sum + = DFS (I) ;}return sum ;} int main () {int I, n, m; while (~ Scanf ("% d", & N, & M) {for (I = 1; I <= N; I ++) T [I]. clear (); While (M --) {int X, Y; scanf ("% d", & X, & Y); t [X]. push_back (Y), t [Y]. push_back (x);} If (! Judge (N) {printf ("NO \ n"); continue;} printf ("% d \ n", getmax (n);} return 0 ;}