Pagini recente » Cod sursa (job #1934728) | Cod sursa (job #28573) | Cod sursa (job #86381) | Cod sursa (job #632437) | Cod sursa (job #2705074)
#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
using namespace std;
ifstream in("cuplaj.in");
ofstream out("cuplaj.out");
const int dim = 10005;
int n,m,e,saturat[2*dim],corespondenta[2*dim];
vector<int> vec[2*dim];
int Cuplaj(int nod)
{
if (saturat[nod]) return 0;
saturat[nod] = 1;
for (auto y:vec[nod])
{
if (corespondenta[y] == -1 || Cuplaj(y))
{
corespondenta[y] = nod;
return 1;
}
}
return 0;
}
int main()
{
int x,y;
in >> n >> m >> e;
for (int i=1; i<=e; i++)
{
in >> x >> y;
vec[x].push_back(n + y);
vec[n + y].push_back(x);
}
for (int i=1; i<=m; i++) corespondenta[n + i] = -1;
for (int i=1; i<=n; i++)
{
memset(saturat, 0, sizeof(saturat));
Cuplaj(i);
}
for (int i=1; i<=m; i++)
{
if (corespondenta[n + i] != -1) out << corespondenta[n + i] << " " << i << "\n";
}
return 0;
}