Pagini recente » Cod sursa (job #3242767) | Cod sursa (job #1414250) | Cod sursa (job #3162713) | Cod sursa (job #1162463) | Cod sursa (job #3225480)
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using ll = long long;
#define pb push_back
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
const int N = 2e4+5;
int n, cnt, cup[N];
vector<int> e[N];
bitset<N> viz;
void read();
bool cupleaza(int);
int main()
{
read();
bool c = 1;
while (c){
c = 0;
viz.reset();
for (int i = 1; i <= n; i++)
if (!cup[i] && !viz[i])
if (cupleaza(i))
c = 1, cnt++;
}
fout << cnt << '\n';
for (int i = 1; i <= n; i++)
if (cup[i]) fout << i << ' ' << cup[i] - n << '\n';
return 0;
}
void read(){
int m, cnte; fin >> n >> m >> cnte;
while (cnte--){
int a, b; fin >> a >> b; b += n;
e[a].pb(b); e[b].pb(a);
}
}
bool cupleaza(int nod){
if (viz[nod]) return 0;
viz[nod] = 1;
for (auto it: e[nod])
if (!cup[it]){
cup[it] = nod;
cup[nod] = it;
return 1;
}
for (auto it: e[nod])
if (cupleaza(cup[it])){
cup[nod] = it;
cup[it] = nod;
return 1;
}
return 0;
}
//17:58