View Code
1 #include2 #include 3 int t,n,m,num,map[1001][1001],a[1001],b[1001]; 4 int dfs(int x) 5 { 6 int i; 7 for(i=1;i<=m;i++) 8 { 9 if(map[x][i]&&b[i]==0)//对其进行覆盖10 {11 b[i]=1;12 if(a[i]==-1||dfs(a[i]))13 {14 a[i]=x;//形成新的交替链15 return 1;16 }17 b[i]=0;18 }19 }20 return 0;21 }22 int main()23 {24 while(scanf("%d",&t),t!=0)25 {26 int i,x,y;27 28 scanf("%d%d",&n,&m);29 memset(map,0,sizeof(map));30 memset(a,(int)-1,sizeof(a));31 for(i=1;i<=t;i++)32 {33 scanf("%d%d",&x,&y);34 map[x][y]=1;35 }36 num=0;37 for(i=1;i<=n;i++)38 {39 memset(b,0,sizeof(b));//每次初始化40 if(dfs(i))41 num++;//记下匹配成功的组数42 }43 printf("%d\n",num);44 }45 return 0;46 }