파일럿 프로그램 페어링 문제
조종사의 각각은, 대부분의 단지 비행기를 구동 할 수 고려, 관계의 팀은, 그래서 한 번만 사용할 수 있습니다
외국인 조종사를 들어 \ (I : S \ xrightarrow { 1} 내가 \)
영국 파일럿의 경우 \ (J : J의 \의 xrightarrow { 1} t \)
관계 집합에 대한 (\ : 나 \ I, J xrightarrow {1} j 개의 \)
에서 \ (S \) 하는 \ (T \) 레코드에 최대 유로를 실행
로 (\ 후) \ 후속 어레이는 지점을 기록
(왜냐하면 입력에 문제 \ (나는 \) 및 (j \) \ 확실히 같지 않은, 즉 레코드 조종사 포인트 일치 된 그래프 최대 일치로 실행될 수 있도록)
\ (\ mathcal {코드} : \)
#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100010
#define int long long
#define debug cout<<__LINE__<<" "<<__FUNCTION__<<"\n"
inline int read(){
int x=0,y=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')y=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*y;
}
int n,m,s,t,dep[N];
int head[N],tot=1,front,used[N];
int ans;
int after[N];
struct Node{
int nxt,to,dis;
}edge[N<<2];
inline void add(int x,int y,int z){
edge[++tot].nxt=head[x];
edge[tot].to=y;
edge[tot].dis=z;
head[x]=tot;
}
queue<int> q;
inline int bfs(){
register int i;
for(i=0;i<=n+1;i++) dep[i]=-1, used[i]=head[i];
dep[s]=0;
q.push(s);
while(!q.empty()){
front=q.front();q.pop();
// cout<<front<<" ";debug;
for(i=head[front];i;i=edge[i].nxt){
if(edge[i].dis&&dep[edge[i].to]==-1){
dep[edge[i].to]=dep[front]+1;q.push(edge[i].to);
}
}
}
// debug;
return dep[t]!=-1;
}
int dfs(int now,int limit){
if(!limit||now==t) return limit;
int flow=0;
for(int &i=used[now],pro;i;i=edge[i].nxt){
if(dep[edge[i].to]==dep[now]+1&&edge[i].dis){
pro=dfs(edge[i].to,min(limit,edge[i].dis));
if(!pro) continue;
edge[i].dis-=pro;
edge[i^1].dis+=pro;
flow+=pro;
limit-=pro;
after[now]=edge[i].to;//记录路径
if(!limit) return flow;
}
}
// cout<<flow<<" ";debug;
// system("pause");
return flow;
}
inline void Dinic(){
while(bfs()){ans+=(dfs(s,10000000001LL));}
}
signed main(){
// freopen("a.in","r",stdin);
// freopen(".out","w",stdout);
m=read();n=read();
s=0;t=n+1;
for(int i=1;i<=m;i++) add(s,i,1),add(i,s,0);
for(int i=m+1;i<=n;i++) add(i,t,1),add(t,i,0);
int x=read(),y=read();
while(x!=-1&&y!=-1){
add(x,y,1);add(y,x,0);
x=read();y=read();
}
Dinic();
if(ans==0){//无解情况
puts("No Solution!");return 0;
}
cout<<ans<<"\n";
for(int i=1;i<=m;i++){
if(after[i]){
cout<<i<<" "<<after[i]<<"\n";
}
}
// fclose(stdin);
// fclose(stdout);
return 0;
}