Pagini recente » Cod sursa (job #1211212) | Cod sursa (job #1728390) | Cod sursa (job #628621) | Cod sursa (job #1264766) | Cod sursa (job #1156463)
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
const char infile[] = "cuplaj.in";
const char outfile[] = "cuplaj.out";
ofstream fout(outfile);
const int MAXN = 100005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
int N, M, E, match[MAXN], mate[MAXN];
Graph G;
bitset <MAXN> Used;
const int lim = (1 << 10);
char buffer[lim];
int pos;
inline void get(int &x) {
x = 0;
while(!('0' <= buffer[pos] && buffer[pos] <= '9')) {
if( ++ pos == lim) {
fread(buffer, 1, lim, stdin);
pos = 0;
}
}
while('0' <= buffer[pos] && buffer[pos] <= '9') {
x = x * 10 + buffer[pos] - '0';
if(++ pos == lim) {
fread(buffer, 1, lim, stdin);
pos = 0;
}
}
}
inline bool pairUp(int Node) {
if(Used[Node])
return 0;
Used[Node] = 1;
for(It it = G[Node].begin(), fin = G[Node].end(); it != fin ; ++ it)
if(!mate[*it] || pairUp(mate[*it])) {
mate[*it] = Node;
match[Node] = *it;
return 1;
}
return 0;
}
int main() {
freopen(infile, "r", stdin);
get(N);
get(M);
get(E);
for(int i = 1 ; i <= E ; ++ i) {
int x, y;
get(x);
get(y);
G[x].push_back(y);
}
int mvc = 0;
for(bool change = true ; change ; ) {
change = false;
Used.reset();
for(int i = 1 ; i <= N ; ++ i)
if(!match[i])
if(pairUp(i)) {
++ mvc;
change = true;
}
}
fout << mvc << '\n';
for(int i = 1 ; i <= N ; ++ i)
if(match[i])
fout << i << ' ' << match[i] << '\n';
fout.close();
return 0;
}