English is not very good, but test instructions is probably given a sequence, each of which gives the possibility of being a couple, and now asks you to find a maximum set of people who cannot be lovers.
The problem-solving idea is the maximal independent set, the maximal independent set = vertex number-Maximum match number;
Since the problem is splitting itself, or dividing a point into 2 parts, the final maximum number of matches is divided by 2;
Be sure to remember the initialization, forget the map array initialization = =, timeout several times;
Give an explanation of the URL: http://dsqiu.iteye.com/blog/1689505
1#include <iostream>2#include <string.h>3 using namespacestd;4 #defineMAXN 20055 intLINKER[MAXN];6 BOOLMAP[MAXN][MAXN];7 intun,vn;8 BOOLVISIT[MAXN];9 BOOLDfsintU//find the augmented path from the leftTen { One intv; A for(v=0; v<vn;v++)//This vertex number starts at 0 and needs to be modified starting from 1 - if(map[u][v]&&!Visit[v]) - { thevisit[v]=true; - if(linker[v]==-1||DFS (Linker[v])) -{//find an augmented path, reverse -linker[v]=u; + return true; - } + } A return false;//don't forget it, always forget it. at } - intHungary () - { - intres=0; - intu; -memset (linker,-1,sizeof(linker)); in for(u=0; u<un;u++) - { tomemset (Visit,false,sizeof(visit)); + if(Dfs (U)) res++; - } the returnRes; * } $ intMain ()Panax Notoginseng { - //freopen ("1068.txt", "R", stdin); the intn,u,v,t; + while(~SCANF ("%d",&N)) A { theUN = VN =N; +memset (Map,false,sizeof(map)); - for(inti =0; i < n; i++) $ { $scanf"%d: (%d)",&u,&t); - while(t--) - { thescanf"%d",&v); -MAP[U][V] =true;Wuyi } the } -printf"%d\n", N-hungary ()/2); Wu } - About return 0; $}View Code
HDU 1068 Girls and Boys