洛谷P2756 飞行员配对方案问题

二分图裸题,找他的最大匹配即可

#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
const int N=1e6+;
int to[N];
struct node
{
int to,nex;
}e[N];
int x,y,tot;
int head[N];
bool vis[N];
void add(int a,int b)
{
e[++tot].to=b;
e[tot].nex=head[a];
head[a]=tot;
}
bool dfs(int x)
{
for(int i=head[x];i;i=e[i].nex)
{
int xx=e[i].to;
if(!vis[xx])
{
vis[xx]=;
if(!to[xx]||dfs(to[xx]))
{
to[xx]=x;
return ;
}
}
}
return ;
}
int main()
{
cin>>n>>m;
cin>>x>>y;
while(x!=-&&y!=-)
{
if(x<=n&&y<=m) add(x,y);
cin>>x;cin>>y;
}
for(int i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
cout<<ans<<endl;
for(int i=n+;i<=m;i++)
{
if(to[i]) cout<<to[i]<<" "<<i<<endl;
}
return ;
}
上一篇:潜水 java类加载器ClassLoader


下一篇:ToString yyyy-MM-dd ,MM 小写的故事。