Pagini recente » Cod sursa (job #2872976) | Cod sursa (job #2465490) | Cod sursa (job #1407883) | Cod sursa (job #2113028) | Cod sursa (job #3032637)
#include <bits/stdc++.h>
#define int long long
//#define mod 1000000007
using namespace std;
ifstream fin ("cuplaj.in");
ofstream fout("cuplaj.out");
int n, m, sol, st[10002], dr[10002];
bool viz[10002];
vector <int> a[10002];
bool cupleaza (int x)
{
if (viz[x])
return 0;
viz[x]=1;
for (auto y:a[x])
if (dr[y]==0)
{
st[x]=y;
dr[y]=x;
sol++;
return 1;
}
for (auto y:a[x])
if (cupleaza(dr[y]))
{
st[x]=y;
dr[y]=x;
return 1;
}
return 0;
}
void cuplaj()
{
bool cuplat=1;
while (cuplat)
{
for (int i=1;i<=n;i++)
viz[i]=0;
cuplat=0;
for (int i=1;i<=n;i++)
if (st[i]==0)
{
if (cupleaza(i))
cuplat=1;
}
}
}
int32_t main()
{
int nrm,x,y;
fin>>n>>m>>nrm;
while (nrm--)
{
fin>>x>>y;
a[x].push_back(y);
}
cuplaj();
fout<<sol<<'\n';
for (int i=1;i<=n;i++)
if (st[i]!=0)
fout<<i<<' '<<st[i]<<'\n';
return 0;
}