const int M = 505;
Graph<M,M*M> g;
class MaxNumMatch{
public:
void Clear(){
CLR(Match,-1); g.Clear();
}
int GetMaxNumMatch(int s,int t){
int MatchNum = 0;
for(int i = s;i <= t;++i){
CLR(Vist,false);
if(Dfs(i)) MatchNum++;
}
return MatchNum;
}
bool Dfs(int cur){
for(int i = g.H[cur];i != -1;i = g.Next[i])
{
if(!Vist[ g.Num[i] ]){
Vist[ g.Num[i] ] = true;
if(Match[ g.Num[i] ] == -1 || Dfs(Match[ g.Num[i] ]))
{
Match[ g.Num[i] ] = cur;
return true;
}
}
}
return false;
}
private:
int Match[M];
bool Vist[M];
};
需要加邻接表模板,头文件string.h,宏定义#define CLR(arr,v) memset(arr,v,sizeof(arr))
需要先调用Clear()函数。