"CODEVS2776" looking for representative yuan

Source: Internet
Author: User

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.

Input

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

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

Sample Input

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

Sample Output

3

Hint

Each test point 1s

n,m<=200

1#include <iostream>2#include <cstring>3 using namespacestd;4 inta[ About][ About];5 intlink1[ About]={0};6 BOOLvis[ About]={false};7 intN,m,x,ans;8 BOOLFindintx)9 {Ten      for(intI=1; i<=m;i++) One         if(A[x][i] &&!Vis[i]) A         { -vis[i]=true; -             if(link1[i]==0|| Find (Link1[i]))//Recursive the             { -link1[i]=x; -                 return true; -             } +         } -     return false; + } A intMain () at { -Cin>>n>>m; -      for(intI=1; i<=n;i++) -     { -          while(1) -         { inCin>>x; -             if(x) a[i][x]=1; to             Else  Break; +         } -     } theans=0; *      for(intI=1; i<=n;i++) $     {Panax Notoginsengmemset (Vis,0,sizeof(VIS));//clear each step before searching -         if(Find (i)) ans++; the     } +cout<<ans; A     return 0; the}

"CODEVS2776" looking for representative yuan

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.