n individuals are divided into m-groups to find the minimum number of people in the group.
Everyone must match only one group, but a group can match many people and therefore belong to multiple matches.
We set a limit that represents the maximum number of people each group can hold. When DFS (U) looks for a match for u, if a group of VV numbers is less than limit, you can match the U and VV, and VV already matches the number of people +1. Otherwise, when the number of people has reached limit, we do DFS for each match of VV, that is, looking for augmentation, if we can find, modify this match, that is, VV and U match.
Then we can have two points limit, when the U set (People's collection) can find a match, then reduce the limit value, otherwise as long as there is a point to find a match, increase the limit value.
Multi-match and binary matching the Hungarian algorithm has a similar notation, except that a CNT array indicates the number of people v has matched, and the linker array also adds one dimension.
1#include <cstdio>2#include <cstring>3#include <vector>4 using namespacestd;5 intn,m;6vector<int> v[1100];7 intlinker[1100][1100],vis[1100],cnt[1100];8 intlimit;9 BOOLDfsintu)Ten { One inti,j; A for(i=0; I<v[u].size (); i++) - { - intvv=V[u][i]; the if(!VIS[VV]) - { -vis[vv]=1; - if(cnt[vv]<limit) + { -linker[vv][cnt[vv]++]=u; + return true; A } at Else - { - for(j=0; j<cnt[vv];j++) - { - if(Dfs (Linker[vv][j])) - { inlinker[vv][j]=u; - return true; to } + } - } the } * } $ return false;Panax Notoginseng } - intMain () the { + inti,j; A Charstr[110000]; the while(SCANF ("%d%d", &n,&m)! =EOF) + { - GetChar (); $ if(n==0&&m==0) Break; $ for(i=0; i<n;i++) - v[i].clear (); - for(i=0; i<n;i++) the { - gets (str);Wuyi intlen=strlen (str); thej=0; -Loop for(; j<len;j++) Wu { - if(str[j]>='0'&&str[j]<='9') About Break; $ } - intnum=0; - BOOLJudge=false; - for(; j<len;j++) A { + if(str[j]>='0'&&str[j]<='9') the { -Judge=true; $num=num*Ten+ (str[j]-'0'); the } the Else Break; the } the if(judge) v[i].push_back (num); - if(J<len)GotoLoop; in } the intL=0, r=N; the while(l<R) About { thelimit= (L+R)/2; thememset (CNT,0,sizeof(CNT)); the for(i=0; i<n;i++) + { -memset (Vis,0,sizeof(Vis)); the if(!dfs (i)) Break;Bayi } the if(i>=n) r=limit; the Elsel=limit+1; - } -printf"%d\n", L); the } the return 0; the}
hdu1669+ two-part multiple match + two points