Skip to content

Instantly share code, notes, and snippets.

@gabber12
Created March 28, 2013 00:34
Show Gist options
  • Save gabber12/5259511 to your computer and use it in GitHub Desktop.
Save gabber12/5259511 to your computer and use it in GitHub Desktop.
#define MAXN 121
vector<vii > g;
vii used;
vii pl, pr;
bool kuhn(int v) {
int k;
if(used[v]) return false;
used[v] = true;
forall(i, 0, g[v].size()) {
k = g[v][i]- MAXN;
if(pr[k] == -1 || kuhn(pr[k])){
pr[k] = v;
pl[v] = k;
return true;
}
}
return false;
}
int match() {
bool pathFound;
pl = vii(MAXN, -1);
pr = vii(MAXN, -1);
used.resize(MAXN);
do {
pathFound = false;
fill(used.begin(), used.end(), 0);
forall(i, 0, MAXN) {
if(!used[i] && pl[i] <0){
pathFound |= kuhn(i);
}
}
}while(pathFound);
int cnt = 0;
forall(i, 0, MAXN)
if(pl[i] != -1)
cnt++;
printf("%d\n", cnt);
return cnt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment