二分图最大匹配,mp映射下字符串。
// #pragma GCC optimize (2)
// #pragma G++ optimize (2)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <unordered_map>
#include <map>
#include <bitset>
#include <set>
#define endl '\n'
#define int long long
#define lowbit(x) x &(-x)
#define rep(i, a, n) for (int i = a; i <= n; i++)
using namespace std;
void TLE() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
const double esp = 1e-5;
const int INF = 2e9;
const int N = 1e5 + 10;
const int mod = 998244353;
typedef pair<int, int> PII;
unordered_map<string, int> mp;
int e[N], ne[N], h[N], cnt;
bool st[N];
int match[N];
vector<int> cows;
void add(int a, int b)
{
e[cnt] = b, ne[cnt] = h[a], h[a] = cnt++;
}
bool find(int x)
{
for (int i = h[x]; i != -1; i = ne[i])
{
int j = e[i];
if (st[j])
continue;
st[j] = true;
if (match[j] == 0 || find(match[j]))
{
match[j] = x;
return true;
}
}
return false;
}
void solve()
{
memset(h, -1, sizeof h);
int n, m, q;
cin >> n >> m >> q;
int idx = 0;
while (q--)
{
string s, p;
cin >> s >> p;
if (!mp.count(s))
{
mp[s] = ++idx;
cows.push_back(mp[s]);
}
if (!mp.count(p))mp[p] = ++idx;
add(mp[s], mp[p]);
}
int ans = 0;
for (auto cow : cows)
{
memset(st, false, sizeof st);
if (find(cow))
ans++;
}
cout << ans << endl;
}
signed main()
{
TLE();
int T;
T = 1;
// int T;cin>>T;
while (T--)
solve();
return 0;
}