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