Pagini recente » Cod sursa (job #3278601) | Cod sursa (job #277243) | Cod sursa (job #609498) | Cod sursa (job #3164996) | Cod sursa (job #2873457)
#include <fstream>
#include <cstring>
#include <vector>
#define N_MAX 10010
using namespace std;
ifstream f("cuplaj.in");
ofstream g("cuplaj.out");
int n, m, n1, n2, e, i, x, y, nr, st[N_MAX], dr[N_MAX], viz[N_MAX];
vector<int > G[N_MAX];
static inline int cupleaza(int nod)
{
if (viz[nod])
return 0;
viz[nod] = 1;
for (auto it : G[nod])
if (!dr[it] || cupleaza(dr[it]))
{
st[nod] = it;
dr[it] = nod;
return 1;
}
return 0;
}
static inline void cuplaj()
{
for (int i = 1; i <= n; ++i)
if (!st[i])
{
if (cupleaza(i))
++nr;
else
{
memset(viz, 0, sizeof(viz));
if (cupleaza(i))
++nr;
}
}
}
int main()
{
ios::sync_with_stdio(false);
f.tie(nullptr);
f >> n >> m >> e;
for (i = 1; i <= e; ++i)
{
f >> x >> y;
G[x].push_back(y);
}
cuplaj();
g << nr << '\n';
for (i = 1; i <= n; ++i)
if (st[i])
g << i << " " << st[i] << '\n';
return 0;
}