Pagini recente » Cod sursa (job #1861005) | Cod sursa (job #1180283) | Cod sursa (job #1434018) | Cod sursa (job #2856148) | Cod sursa (job #2679629)
#include <fstream>
#define fisier "cuplaj"
std::ifstream in(fisier ".in");
std::ofstream out(fisier ".out");
const int N = 15001;
int R[N], L[N], s;
#include <vector>
std::vector<int> V[N];
#include <bitset>
std::bitset<N> E;
bool dfs(int);
bool cup(int l, bool p)
{
for (int r: V[l])
if (p? dfs(L[r]): not L[r])
{
L[r] = l, R[l] = r;
if (not p) s++;
return true;
}
return false;
}
bool dfs(int l)
{
if (E[l]) return false;
E[l] = true;
return cup(l, false) or cup(l, true);
}
int main()
{
int n, m, c; in >> n >> m >> c;
while (c--)
{
int a, b; in >> a >> b;
V[a].push_back(b);
}
do {
E = c = false;
for (int l = 1; l <= n; l++)
c |= not R[l] and dfs(l);
} while (c);
out << s << '\n';
for (int l = 1; l <= n; l++)
if (R[l]) out << l << ' ' << R[l] << '\n';
}