Pagini recente » Cod sursa (job #1527408) | Cod sursa (job #280027) | Cod sursa (job #765482) | Cod sursa (job #3185609) | Cod sursa (job #2695422)
#include <fstream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
ifstream cin("cuplaj.in");
ofstream cout("cuplaj.out");
const int N = 1e4 + 5;
int n, m, e, Left[N], Right[N], nr_pair_matched;
vector<int> a[N];
bool viz[N];
bool dfs(int node)
{
if (viz[node])
{
return false;
}
viz[node] = 1;
for (int nei : a[node])
{
if (!Right[nei] || dfs(Right[nei]))
{
Left[node] = nei;
Right[nei] = node;
return true;
}
}
return false;
}
int main()
{
std::cin >> n >> m >> e;
for(int i = 1 ; i <= e ; i++)
{
int x, y;
std::cin >> x >> y;
a[x].push_back(y);
}
bool found_pair = true;
while (found_pair)
{
found_pair = false;
for (int i = 1; i <= n; ++i)
{
viz[i] = 0;
}
for (int i = 1; i <= n; ++i)
{
if (!Left[i] && dfs(i))
{
found_pair = true;
nr_pair_matched++;
}
}
}
std::cout << nr_pair_matched << '\n';
/*
for (int i = 1; i <= n; ++i)
{
if (Left[i])
{
std::cout << i << ' ' << Left[i] << '\n';
}
}
*/
return 0;
}