HDU 1068 Girls and Boys

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.