Pagini recente » Cod sursa (job #2722262) | Cod sursa (job #2134891) | Cod sursa (job #3039124) | Cod sursa (job #1713812) | Cod sursa (job #2669262)
#include <fstream>
#define fisier "cuplaj"
std::ifstream in(fisier ".in");
std::ofstream out(fisier ".out");
const int N = 10001, M = N;
int L[M], R[N], s;
#include <vector>
std::vector<int> V[N];
#include <bitset>
std::bitset<N> E;
bool gasit(int);
bool cauta(int l, bool sat)
{
for (int r: V[l])
if (sat? gasit(L[r]): not L[r])
{
L[r] = l; R[l] = r;
if (not sat) s++;
return true;
}
return false;
}
bool gasit(int l)
{
if (E[l])
return false;
E[l] = true;
return cauta(l, false) or cauta(l, true);
}
int main()
{
int n, m, e;
in >> n >> m >> e;
while (e--)
{
int a, b;
in >> a >> b;
V[a].push_back(b);
}
bool cup;
do
{
E = cup = false;
for (int l = 1; l <= n; l++)
cup |= not R[l] and gasit(l);
}
while (cup);
out << s << '\n';
for (int l = 1; l <= n; l++)
if (R[l])
out << l << ' ' << R[l] << '\n';
}