hdu 2063 赤裸裸的匈牙利算法

题目没啥说的,赤裸裸的匈牙利算法,可恶的是题目输入描述不清,还以为每组输入后都有一个0呢,害得我RE了一次,鄙视一下出题者,哈哈!

/*
* hdu2063/linux.cpp
* Created on: 2011-9-1
* Author : ben
*/
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<cmath>
#include
<algorithm>
usingnamespace std;

constint MAXN =555;

int n, m, match[MAXN];
bool visit[MAXN], map[MAXN][MAXN];

bool dfs(int k) {
int t;
for (int i =0; i < m; i++) {
if (map[k][i] &&!visit[i]) {
visit[i]
=true;
t
= match[i];
match[i]
= k;
if (t ==-1|| dfs(t)) {
returntrue;
}
match[i]
= t;
}
}
returnfalse;
}

void work() {
int K, t1, t2, ans;
while (scanf("%d%d%d", &K, &n, &m) ==3) {
memset(map,
false, sizeof(map));
for (int i =0; i < K; i++) {
scanf(
"%d%d", &t1, &t2);
map[t1
-1][t2 -1] =true;
}
memset(match,
-1, sizeof(match));
ans
=0;
for(int i =0; i < n; i++) {
memset(visit,
false, sizeof(visit));
if(dfs(i)) {
ans
++;
}
}
printf(
"%d\n", ans);
}
}

int main() {
#ifndef ONLINE_JUDGE
freopen(
"data.in", "r", stdin);
#endif
work();
return0;
}

你可能感兴趣的:(HDU)