Pagini recente » Cod sursa (job #1408239) | Cod sursa (job #2058327) | Cod sursa (job #2576079) | Cod sursa (job #1650424) | Cod sursa (job #2260073)
#include <bits/stdc++.h>
using namespace std;
typedef long long Int;
ifstream f("cuplaj.in");
ofstream g("cuplaj.out");
const int N = 10010;
int n,m,e,cuplari;
vector<int> v[N];
bitset<N> viz;
int st[N],dr[N];
bool cuplez(int);
int main()
{
f>>n>>m>>e;
for(; e; e--)
{
int x,y;
f>>x>>y;
v[x].push_back(y);
}
bool ok=true;
while(ok)
{
ok=false;
viz.reset();
for(int i=1; i<=n; i++)
ok|=cuplez(i);
}
g<<cuplari<<'\n';
for(int i=1;i<=n;i++)
if(st[i])
g<<i<<' '<<st[i]<<'\n';
return 0;
}
bool cuplez(int nod)
{
if(viz[nod])return false;
viz[nod]=1;
for(auto it:v[nod])
if(!st[it])
{
st[it]=nod;
dr[nod]=it;
cuplari++;
return true;
}
for(auto it:v[nod])
if(cuplez(st[it]))
{
st[it]=nod;
dr[nod]=it;
return true;
}
return false;
}