注意POJ数组越界可能返回TLE!!!
网络流的maxn大小要注意
其他没什么了 裸二分答案+isap乱搞
不过复杂度没搞懂 V=1e3 E = 1e5 那ISAP的O(V^2E)怎么算都不行啊
/*--------------------------------------------------------------------------------------*/ #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T;
const int maxn = ;
const int maxm = ;
//map<int ,string > mp;
vector <int> save[maxn]; struct Edge{
int to,next,cap,flow;
}edge[maxm]; int head[maxn],tot;
int uN = ;
int gap[maxn],dep[maxn],pre[maxn],cur[maxn]; void init()
{
tot = ;
memset(head,-,sizeof head);
} void add_edge(int u,int v,int w,int rw = )
{
//printf("%d->%d %d\n",u,v,w);
edge[tot].to = v;edge[tot].cap = w;edge[tot].next = head[u];
edge[tot].flow = ;head[u] = tot++;
edge[tot].to = u;edge[tot].cap = rw;edge[tot].next = head[v];
edge[tot].flow = ;head[v] = tot++;
}
int Q[maxn];
void BFS(int st,int ed)
{
memset(dep,-,sizeof dep);
memset(gap,,sizeof gap);
gap[] = ;
int front = ,rear = ;
dep[ed] = ;
Q[rear++] = ed;
while(front != rear)
{
int u = Q[front++];
for(int i=head[u];~i;i=edge[i].next)
{
int v = edge[i].to;
if(dep[v] != -) continue;
Q[rear++] = v;
dep[v] = dep[u] + ;
gap[dep[v]] ++;
}
}
}
int S[maxn]; int sap(int st,int ed)
{
BFS(st,ed);
memcpy(cur,head,sizeof head);
int top = ;
int u = st; int ans = ;
while(dep[st] < uN)
{
if(u == ed)
{
int Min = INF;
int inser;
for(int i=;i<top;i++)
{
if(Min > edge[S[i]].cap - edge[S[i] ].flow)
{
Min = edge[S[i]].cap - edge[S[i]].flow;
inser=i;
}
}
for(int i=;i<top;i++)
{
edge[S[i]].flow += Min;
edge[S[i]^].flow -= Min;
}
ans += Min;
top = inser;
u = edge[S[top]^].to;
continue;
}
bool flag = false;
int v;
for(int i=cur[u];~i;i=edge[i].next)
{
v = edge[i].to;
if(edge[i].cap - edge[i].flow && dep[v]+ == dep[u])
{
flag = true;
cur[u] = i;
break;
}
}
if(flag)
{
S[top++] = cur[u];
u = v;
continue;
}
int Min = uN;
for(int i=head[u];~i;i=edge[i].next)
{
if(edge[i].cap - edge[i].flow && dep[edge[i].to] < Min)
{
Min = dep[edge[i].to];
cur[u] = i;
}
}
gap[dep[u]] --;
if(!gap[dep[u]]) return ans;
dep[u] = Min + ;
gap[dep[u] ]++;
if(u != st) u = edge[S[--top]^].to;
}
return ans;
} int check(int mid)
{
uN = N+M+;
init();
for(int i=;i<N;i++)
{
add_edge(N+M,i,);
for(int j=;j<save[i].size();j++)
{
add_edge(i,save[i][j]+N,);
}
}
for(int i=;i<M;i++)
{
add_edge(N+i,N+M+,mid);
} int res = sap(N+M,N+M+);
//printf("mid:%d res:%d\n",mid,res);
if(res == N) return true;
else return false;
} int solve()
{
int L = ,R = *N,mid;
while(L <= R)
{
mid = (L+R)>>;
if(check(mid)) R = mid-;
else L = mid+;
}
//printf("%d %d\n",L,R);
return L;
} int main()
{
while(scanf("%d%d",&N,&M) && N+M)
{
char s[];
//mp.clear();
for(int i=;i<maxn;i++) save[i].clear();
for(int i=;i<N;i++)
{
scanf("%s",s);
char c = getchar();
if(c != ' ') continue;
int num = -;
while((c = getchar()) && c !='\n')
{
if(isdigit(c))
{
if(num == -) num = ;
num *= ;num += c-'';
}
else if(c == ' ')
{
save[i].push_back(num);
num = -;
}
}
if(num != -) save[i].push_back(num);
}
if(M == || N == ) printf("0\n");
else printf("%d\n",solve());
}
}