Pagini recente » Cod sursa (job #3002349) | Cod sursa (job #3145732) | Cod sursa (job #1610078) | Cod sursa (job #1214177) | Cod sursa (job #1843038)
#include <bits/stdc++.h>
using namespace std;
vector <int> graf[10001];
int boss_left[10001], boss_right[10001], viz[10001], rasp;
bool cuplaj (int nod)
{
if (viz[nod] == 1)
return 0;
viz[nod] = 1;
for (auto x:graf[nod])
{
if (boss_right[x] == 0)
{
boss_left[nod] = x;
boss_right[x] = nod;
return 1;
}
}
for (auto x:graf[nod])
{
if (cuplaj(boss_right[x]))
{
boss_left[nod] = x;
boss_right[x] = nod;
return 1;
}
}
return 0;
}
int main()
{
int n, m, x, y, k;
ifstream fin ("cuplaj.in");
ofstream fout ("cuplaj.out");
fin >> n >> m >> k;
for (int i = 0; i<k; ++i)
{
fin >> x >> y;
graf[x].push_back(y);
}
for (int i = 1; i<=n; ++i)
{
if (boss_left[i] == 0)
{
memset(viz, 0, sizeof(viz));
rasp += cuplaj(i);
}
else ++rasp;
}
fout << rasp << '\n';
for (int i = 1; i<=n; ++i)
if (boss_left[i])
fout << i << " " << boss_left[i] << '\n';
return 0;
}