#line 1 "a.cpp" #include #include #include using namespace std; #line 3 "/home/kotatsugame/library/graph/bimatch.cpp" struct bimatch{ int n; vector >G; vectormatch; vectorused; bimatch(int _n=0):n(_n),G(n),match(n),used(n){} void add_edge(int u,int v) { G[u].push_back(v); G[v].push_back(u); } bool dfs(int v) { used[v]=true; for(int u:G[v]) { int w=match[u]; if(w<0||!used[w]&&dfs(w)) { match[v]=u; match[u]=v; return true; } } return false; } int count() { int ans=0; bool flag=true; fill(match.begin(),match.end(),-1); while(flag) { flag=false; fill(used.begin(),used.end(),false); for(int v=0;v>N>>M; vector > >A(N*M); for(int i=0;i>A[i*M+j].first; A[i*M+j].second=make_pair(i,j); } sort(A.begin(),A.end()); int ans=0; for(int i=0;i