Pagini recente » Cod sursa (job #1985024) | Cod sursa (job #3177060) | Cod sursa (job #1384774) | Cod sursa (job #838679) | Cod sursa (job #558830)
Cod sursa(job #558830)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const char iname[] = "cuplaj.in";
const char oname[] = "cuplaj.out";
const int nmax = 10200;
ifstream fin(iname);
ofstream fout(oname);
vector<int> Gr[nmax];
int L[nmax], R[nmax], i, k, c, n, m, e, x, y;
int viz[nmax];
int am_cuplat;
int pair_up(int nod)
{
if(viz[nod])
return 0;
viz[nod] = 1;
for(vector<int>::iterator it = Gr[nod].begin(); it != Gr[nod].end(); ++it)
{
if(pair_up(R[*it]) || R[*it] == 0)
{
L[nod] = *it;
R[*it] = nod;
return 1;
}
}
return 0;
}
int main()
{
fin >> n >> m >> e;
for(i = 1; i <= e; i ++)
{
fin >> x >> y;
Gr[x].push_back(y);
Gr[y].push_back(x);
}
am_cuplat = 1;
while(am_cuplat)
{
am_cuplat = 0;
for(i = 1; i <= n; i ++)
{
memset(viz, 0, sizeof(viz));
if(!L[i])
if(pair_up(i))
{
++ c;
am_cuplat = 1;
}
}
}
fout << c << "\n";
for(i = 1; i <= n; i ++)
if(L[i])
fout << i << " " << L[i] << "\n";
return 0;
}