Pagini recente » Cod sursa (job #350983) | Cod sursa (job #615390) | Cod sursa (job #895818) | Cod sursa (job #3243304) | Cod sursa (job #2695904)
#include <bits/stdc++.h>
#define pb push_back
#define Nmax 10005
#define Mmax 10005
using namespace std;
vector < int > V[10005];
int N, M, E, x, y, Cmax, L[Nmax], R[Mmax];
bool Marc[Nmax], ok;
ifstream f ("cuplaj.in");
ofstream g ("cuplaj.out");
int cuplez (int x)
{
Marc[x] = true;
for(auto y: V[x])
if(!R[y])
{
L[x] = y;
R[y] = x;
return 1;
}
for(auto y: V[x])
if(!Marc[R[y]] && cuplez(R[y]))
{
L[x] = y;
R[y] = x;
return 1;
}
return 0;
}
void cuplaj()
{
bool ok = true;
while (ok)
{
ok = false;
for(int i = 1; i <= N; i++)
Marc[i] = false;
for(int i = 1; i <= N; i++)
if(!L[i] && !Marc[i] && cuplez(i))
{
ok = true;
Cmax++;
}
}
}
int main()
{
f >> N >> M >> E;
for ( ; E; E--)
{
f >> x >> y;
V[x].pb(y);
}
cuplaj();
g << Cmax << '\n';
for (int i = 1; i <= N; ++i)
if(L[i]) g << i << " " << L[i] << '\n';
f.close();
g.close();
return 0;
}