Link:
http://acm.hdu.edu.cn/showproblem.php?pid=2389
You can't use Hungary, you'll tel, with Hopcroft-karp.
Hopcroft-karp Courseware
Used to look for an augmented path, this is to find all the augmented roads, and use BFS for layering
Code:
#include <cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<queue>#include<stack>#include<algorithm>using namespacestd;#defineN 3100#defineINF 0XFFFFFFFstructnode{intx, y, s;} X[n], y[n];structnode{intV, Next;} A[n*N];intHead[n], CNT, N, M;BOOLUsed[n];intMx[n], my[n], depth;///The matched endpoint of the record, 0 indicates an unmatchedintDx[n], dy[n];///when a BFS is layered, the record point is in the same layer, 1 means not layeredvoidInit () {CNT=0; memset (Head,-1,sizeof(head));}voidADD (intUintv) {A[CNT].V=v; A[cnt].next=Head[u]; Head[u]= cnt++;}BOOLBFS ()///if you find that Y has an augmented path on this side, return 1, or 0.{Queue<int> Q; depth =INF; memset (DX,-1,sizeof(DX)); memset (DY,-1,sizeof(DY)); for(intI=1; i<=n; i++) { if(Mx[i] = =false) {Dx[i]=0; Q.push (i); } } while(Q.size ()) {intU =Q.front (); Q.pop (); if(Dx[u] > depth) Break;///We 've found the augmented path, no need to look for the lower for(intJ=head[u]; j!=-1; j=A[j].next) { intv =a[j].v; if(Dy[v] = =-1) {Dy[v]= Dx[u] +1; if(My[v] = =false) Depth=Dy[v]; Else{dx[My[v]]= Dy[v] +1; Q.push (My[v]); } } } } if(Depth = =INF)return false; return true;}BOOLFind (inti) { for(intJ=head[i]; j!=-1; j=A[j].next) { intv =a[j].v; if(!used[v] && dx[i] = = dy[v]-1) {Used[v]=true; if(My[v] && dy[v] = =depth)Continue;///not on the next level because the lower layer has not been augmented if( ! MY[V] | |Find (My[v])) {My[v]=i; Mx[i]=v; return true; } } } return false;}intKarp () {intAns =0; memset (Mx,false,sizeof(Mx)); memset (My,false,sizeof(My)); while(BFS () = =true ) {///If there is an augmented pathmemset (Used,false,sizeof(used)); for(intI=1; i<=n; i++) { if( ! Mx[i] && Find (i) = =true) ans++; } } returnans;}intMain () {intT, icase=1; scanf ("%d", &t); while(t--) { intTime , I, J; scanf ("%d%d", &time, &N); Init (); for(i=1; i<=n; i++) {scanf ("%d%d%d", &x[i].x, &X[I].Y, &x[i].s); X[i].s= x[i].s*x[i].s*time*Time ; } scanf ("%d", &m); for(i=1; i<=m; i++) {scanf ("%d%d", &y[i].x, &y[i].y); for(j=1; j<=n; J + +) { intD = (y[i].x-x[j].x) * (y[i].x-x[j].x) + (Y[I].Y-X[J].Y) * (y[i].y-x[j].y); if(d <=x[j].s) Add (J, I); } } intAns =Karp (); printf ("Scenario #%d:\n%d\n\n", icase++, ans); } return 0;}
(Matching hopcroft-karp algorithm) Rain on your Parade--Hdu--2389