Hungarian algorithm Codevs 2776 looking for representative meta

Source: Internet
Author: User

Codevs 2776 Looking for representative Yuantime limit: 1 sspace limit: 256000 KBtitle level: Golden GoldTitle Description Description

Guangzhou second middle Su Yuan Experimental school has a total of n societies, numbered 1 to n respectively.
Guangzhou second middle Su Yuan Experimental school has a total of M individuals, which are numbered 1 to M respectively. Each person may participate in one or more societies, or may not participate in any community.
Each community needs to choose a representative. Brother Qian wants more people to be represented.

Enter a description Input Description

The first line enters two numbers n and M.
The following n rows have a number of rows per line, and these numbers are positive integers that do not exceed M. Where the number of line I represents all members of the community I. Each line ends with a 0.

Output description Output Description

The maximum number of people that can be represented is the output.

Sample input Sample Input

4 4
1 2 0
1 2 0
1 2 0
1 2 3) 4 0

Sample output Sample Output

3

Data range and Tips Data Size & Hint

Each test point 1s

Data range
n,m<=200

1 /*Note: Link is a key word for Linux systems*/2#include <iostream>3 using namespacestd;4#include <cstdio>5 #defineN 2106#include <cstring>7#include <vector>8 inthead[n],link[n],n,m,ans=0, t=-1;9 BOOLVisit[n];Ten structedge{ One     intV,last; A }; -Vector<edge>Edge; - voidAdd_edge (intUintv) the { - Edge E; -e.v=v;e.last=Head[u]; - Edge.push_back (e); +head[u]=++T; - } + voidinput () A { atscanf"%d%d",&n,&m); -     intx; -memset (head,-1,sizeof(head)); -      for(intI=1; i<=n;++i) -     { -scanf"%d",&x); in          while(x) -         { to Add_edge (i,x); +scanf"%d",&x); -         } the     } * } $ BOOLXylfind (intk)Panax Notoginseng { -      for(intl=head[k];l!=-1; l=edge[l].last) the     { +         if(!VISIT[EDGE[L].V])/*if the person has not visited it, it means that it is being occupied, or that space has failed.*/ A         { thevisit[edge[l].v]=true;/*If this person is not a representative of the community, or can change the representative of the society represented by the person, then the current person is established as a representative of the community*/ +             if(! link[edge[l].v]| |Xylfind (LINK[EDGE[L].V])) -             { $link[edge[l].v]=K; $                 return true; -             } -         } the     } -     return false;Wuyi } the intMain () - { Wu  - input (); About      for(intI=1; i<=n;++i)/*find a representative for every community*/ $     { -memset (Visit,false,sizeof(visit)); -         /*don't forget to initialize the visit array every time, because each time we match an I, it's possible to show a lot of people visit*/ -                 if(Xylfind (i)) ans++; A     } +printf"%d\n", ans); the     return 0; - } $  

Hungarian algorithm Codevs 2776 looking for representative meta

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.