Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define unmatched -1
- #define MAX 505
- #define p push_back
- int n,m,num;
- vector < int > v[MAX];
- int match[MAX];
- bool vis[MAX];
- bool dfs(int x)
- {
- vis[x]=1;
- for(int i=0;i<v[x].size();++i){
- int node = v[x][i];
- if(vis[node])continue;
- vis[node]=1;
- if(match[node]==unmatched || dfs(match[node])){
- match[x]=node;
- match[node]=x;
- return 1;
- }
- }
- return 0;
- }
- int main()
- {
- while(cin>>n>>m>>num){
- fill ( match , match+MAX , unmatched);
- for(int i=0;i<num;++i){
- int fr,to;
- scanf("%d %d",&fr,&to);
- v[fr].p(to+n);
- v[to+n].p(fr);
- }
- int sizematching=0;
- for(int i=0;i<n;++i){
- if(match[i]==unmatched){
- fill(vis , vis+MAX , 0);
- if(dfs(i)){
- sizematching++;
- }
- }
- }
- cout<<sizematching<<endl;
- for(int i=0;i<n;++i){
- if(match[i]!=unmatched){
- cout<<i<<" "<<match[i]-n<<endl;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement