Pagini recente » Cod sursa (job #1374944) | Cod sursa (job #482879) | Cod sursa (job #1719278) | Cod sursa (job #283749) | Cod sursa (job #2366814)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cuplaj.in");
ofstream fout ("cuplaj.out");
const int Nmax = 1e4 + 5;
int a[Nmax] , f , n , m , st[Nmax] , dr[Nmax] , ans;
vector < int > L[Nmax];
bitset < Nmax > viz;
bool ok;
inline bool Cuplaj(int nod)
{
if(viz[nod])
return false;
viz[nod] = 1;
for(auto it : L[nod])
if(!dr[it])
{
st[nod] = it;
dr[it] = nod;
return true;
}
for(auto it : L[nod])
if(dr[it] && Cuplaj(dr[it]))
{
st[nod] = it;
dr[it] = nod;
return true;
}
return false;
}
int main()
{
int x , y;
fin >> f >> n >> m;
for(int i = 1 ; i <= m ; i++)
fin >> x >> y , L[x].push_back(y);
ok = true;
while(ok)
{
ok = false;
viz.reset();
for(int i = 1 ; i <= f ; i++)
if(!st[i] && Cuplaj(i))
++ans , ok = true;
}
fout << ans << "\n";
for(int i = 1 ; i <= f ; i++)
if(st[i])
fout << i << " " << st[i] << "\n";
fin.close();
fout.close();
}