Pagini recente » Cod sursa (job #2824990) | Cod sursa (job #2171452) | Cod sursa (job #163310) | Cod sursa (job #2280364) | Cod sursa (job #2786455)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
int n, m, e, cnt;
int viz[10005], st[10005], dr[10005];
vector <int> V[10005];
void Citire()
{
int x, y, i;
fin >> n >> m >> e;
for(i = 1;i <= e;i++)
{
fin >> x >> y;
V[x].push_back(y);
}
}
int Cuplare(int nod)
{
if(viz[nod])
return 0;
viz[nod] = 1;
for(auto x : V[nod])
if(dr[x] == 0)
{
st[nod] = x;
dr[x] = nod;
return 1;
}
for(auto x : V[nod])
if(Cuplare(dr[x]))
{
st[nod] = x;
dr[x] = nod;
return 1;
}
return 0;
}
void Solve()
{
int i, j, ok;
ok = 1;
while(ok)
{
ok = 0;
for(i = 1;i <= n;i++)
viz[i] = 0;
for(i = 1;i <= n;i++)
if(st[i] == 0 && Cuplare(i))
{
cnt++;
ok = 1;
}
}
fout << cnt << "\n";
for(i = 1;i <= n;i++)
if(st[i])
fout << i << " " << st[i] << "\n";
}
int main()
{
Citire();
Solve();
return 0;
}