Pagini recente » Cod sursa (job #1376225) | Cod sursa (job #639126) | Cod sursa (job #822300) | Cod sursa (job #2728127) | Cod sursa (job #2173124)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
int st[10005], dr[10005], n, m, e;
bool viz[10005];
vector <int> L[10005];
inline bool Cupleaza(int x)
{
if(viz[x] == 1) return 0;
viz[x] = 1;
for(auto i : L[x])
if(dr[i] == 0)
{
st[x] = i;
dr[i] = x;
return 1;
}
for(auto i : L[x])
if(Cupleaza(dr[i]))
{
st[x] = i;
dr[i] = x;
return 1;
}
return 0;
}
void Citire()
{
int x, y;
fin >> n >> m >> e;
for(int i = 1; i <= e; i++)
{
fin >> x >> y;
L[x].push_back(y);
}
bool gata = 0;
int cuplaje = 0;
while(!gata)
{
gata = 1;
for(int i = 1; i <= n; i++)
viz[i] = 0;
for(int i = 1; i <= n; i++)
if(st[i] == 0 && Cupleaza(i))
cuplaje++,
gata = 0;
}
fout << cuplaje << "\n";
for(int i = 1; i <= n; i++)
if(st[i] != 0)
fout << i << " " << st[i] << "\n";
}
int main()
{
Citire();
return 0;
}