#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 510, M = 1010;
int h[N], e[M], ne[M], idx;
int n1, n2, m;
bool st[N];
int match[N];
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}
bool find(int x) {
for (int i = h[x]; i != -1; i = ne[i]) {
int j = e[i];
if (!st[j]) {
st[j] = true;
if (match[j] == 0 || find(match[j])) {
match[j] = x;
return true;
}
}
}
return false;
}
int main() {
while (~scanf("%d", &m)) {
if (m == 0)
break;
memset(h, -1, sizeof h);
idx = 0;
memset(match, 0, sizeof match);
scanf("%d%d", &n1, &n2);
while (m -- ) {
int a, b;
scanf("%d%d", &a, &b);
add(a, b);
}
int res = 0;
for (int i = 1; i <= n1; i ++ ) {
memset(st, false, sizeof st);
if (find(i))
res ++ ;
}
printf("%d\n", res);
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 510, M = 10010;
int h[N], e[M], ne[M], idx;
int n1, n2, m;
bool st[N];
int match[N];
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}
bool find(int x) {
for (int i = h[x]; i != -1; i = ne[i]) {
int j = e[i];
if (!st[j]) {
st[j] = true;
if (match[j] == 0 || find(match[j])) {
match[j] = x;
return true;
}
}
}
return false;
}
int main() {
scanf("%d%d", &n1, &m);
n2 = n1;
memset(h, -1, sizeof h);
while (m -- ) {
int a, b;
scanf("%d%d", &a, &b);
add(a, b);
}
int res = 0;
for (int i = 1; i <= n1; i ++ ) {
memset(st, false, sizeof st);
if (find(i))
res ++ ;
}
printf("%d\n", res);
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 410;
int dx[] = {0, -1, 0, 1}, dy[] = {-1, 0, 1, 0};
int n, m;
bool st[N];
int match[N];
int mp[N][N];
bool g[N][N];
char op;
int id;
int n1, n2;
bool find(int x) {
for (int i = 1; i <= n2; i ++ )
if (g[x][i]) {
if (!st[i]) {
st[i] = true;
if (match[i] == 0 || find(match[i])) {
match[i] = x;
return true;
}
}
}
return false;
}
int main() {
int T;
scanf("%d", &T);
while (T -- ) {
memset(match, 0, sizeof match);
memset(g, false, sizeof g);
memset(mp, 0, sizeof mp);
id = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i ++ )
for (int j = 0; j < m; j ++ ) {
cin >> op;
if (op == '*')
mp[i][j] = ++ id;
else
mp[i][j] = 0;
}
n1 = n2 = id;
for (int i = 0; i < n; i ++ )
for (int j = 0; j < m; j ++ )
if (mp[i][j])
for (int k = 0; k < 4; k ++ ) {
int x = i + dx[k], y = j + dy[k];
if (mp[x][y])
g[mp[i][j]][mp[x][y]] = true;
}
int res = 0;
for (int i = 1; i <= n1; i ++ ) {
memset(st, false, sizeof st);
if (find(i))
res ++ ;
}
printf("%d\n", id - res / 2);
}
return 0;
}