Pagini recente » Cod sursa (job #709033) | Cod sursa (job #1436115) | Cod sursa (job #1165555) | Cod sursa (job #1182864) | Cod sursa (job #1414402)
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <fstream>
#include <cctype>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
vector<int> V[10001];
int L[10001];
int R[10001];
bitset<10001> used;
bool cuplaj(int node)
{
if(used[node])
return false;
used[node] = true;
for(vector<int>::iterator it = V[node].begin(); it != V[node].end(); it++)
if(!R[*it] || cuplaj(R[*it]))
{
L[node] = *it;
R[*it] = node;
return true;
}
return false;
}
int main()
{
//freopen("1.in");
//freopen("1.out");
int n,m,e,x,y;
fin>>n>>m>>e;
for(int i = 1; i <= e; i++)
{
fin>>x>>y;
V[x].push_back(y);
}
bool ok = true;
int res = 0;
while(ok)
{
ok = false;
used.reset();
for(int i = 1; i <= n; i++)
if(!L[i] && cuplaj(i))
{
ok = true;
res++;
}
}
fout<<res<<'\n';
for(int i = 1; i <= n; i++)
if(L[i])
fout<<i<<' '<<L[i]<<'\n';
return 0;
}
//FILE!!!