Pagini recente » Cod sursa (job #240656) | Cod sursa (job #229352) | Cod sursa (job #227724) | Cod sursa (job #823085) | Cod sursa (job #3305555)
#pragma GCC optimize("O3,unroll-loops,fast-math")
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int dm=1e4+55;
int n,m,e,x,y,sol,st[dm],dr[dm];
bitset<dm>vz;
vector<int>a[dm];
bool cup(int x)
{
if(vz[x])return 0;
vz[x]=1;
for(auto it:a[x])
if(dr[it]==0)
{
st[x]=it;
dr[it]=x;
sol++;
return 1;
}
for(auto it:a[x])
if(cup(dr[it]))
{
st[x]=it;
dr[it]=x;
return 1;
}
return 0;
}
int main()
{
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
fin>>n>>m>>e;
while(e--)
{
fin>>x>>y;
a[x].pb(y);
}
bool cuplat=1;
while(cuplat)
{
vz.reset();
cuplat=0;
for(int i=1;i<=n; ++i)
if(st[i]==0)cuplat|=cup(i);
}
fout<<sol<<'\n';
for(int i = 1;i<=n; ++i)
if(st[i])fout<<i<<" "<<st[i]<<'\n';
return 0;
}