还是一道明显的最大流. #include<iostream> using namespace std; const int MAXN=100,INF=1000000; int c[MAXN*5][MAXN*5]; int h[MAXN*5],vh[MAXN*5]; int augc,flow; bool found; int ln,lf,ld,ll; int n,f,d; void aug(const int p); int main() { int i,j,k; int x,y; scanf("%d%d%d",&n,&f,&d); lf=1; ln=1+f; ld=1+f+n; ll=1+f+n+d+1; for(i=1;i<=f;i++) c[1][i+lf]=1; for(i=1;i<=d;i++) c[i+ld][ll]=1; for(i=1;i<=n;i++) { scanf("%d%d",&x,&y); for(j=1;j<=x;j++) { scanf("%d",&k); c[k+lf][i+ln]=1; } for(j=1;j<=y;j++) { scanf("%d",&k); c[i+ln][k+ld]=1; } } vh[0]=ll; while(h[1]<ll) { found=false; augc=INF; aug(1); } printf("%d/n",flow); system("pause"); return 0; } void aug(const int p) { int minh,augco,i; minh=ll-1; augco=augc; if(h[1]>=ll) return; if(p==ll) { flow+=augc; found=true; return; } for(i=1;i<=ll;i++) { if(c[p][i]<=0) continue; if(h[p]==h[i]+1) { augc=min(augc,c[p][i]); aug(i); if(h[1]==ll) return; if(found) break; augc=augco; } minh=min(minh,h[i]); } if(!found) { vh[h[p]]--; if(vh[h[p]]==0) { h[1]=ll; return; } h[p]=minh+1; vh[h[p]]++; } else { c[p][i]-=augc; c[i][p]+=augc; } return; }