Pagini recente » Cod sursa (job #2120334) | Cod sursa (job #109512) | Cod sursa (job #385601) | Cod sursa (job #1524037) | Cod sursa (job #2614470)
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int NMAX = 10000;
const int MMAX = 10000;
int l[NMAX + 5] , r[MMAX + 5] , viz[NMAX + 5];
vector <int> G[NMAX + 5];
int path(int u)
{
if(viz[u] == 1)
return 0;
viz[u] = 1;
for(int j = 0 ; j < G[u].size() ; j ++)
{
int v = G[u][j];
if(!r[v] || path(r[v]))
{
l[u] = v;
r[v] = u;
return 1;
}
}
return 0;
}
int main()
{
freopen("cuplaj.in" , "r" , stdin);
freopen("cuplaj.out" , "w" , stdout);
int n , m , e , x , y , i , cuplaj , gasit;
scanf("%d%d%d" , &n , &m , &e);
for(i = 1 ; i <= e ; i ++)
{
scanf("%d%d" , &x , &y);
G[x].push_back(y);
}
cuplaj = 0;
do
{
gasit = 0;
memset(viz , 0 , sizeof(viz));
for(i = 1 ; i <= n ; i ++)
if(!l[i] && path(i))
{
gasit = 1;
cuplaj ++;
}
}
while(gasit);
printf("%d\n" , cuplaj);
for(i = 1 ; i <= n ; i ++)
if(l[i])
printf("%d %d\n" , i , l[i]);
return 0;
}