社区讨论
这个数据有点水啊……
P2756飞行员配对方案问题参与者 5已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mi6mf251
- 此快照首次捕获于
- 2025/11/20 07:15 4 个月前
- 此快照最后确认于
- 2025/11/20 07:15 4 个月前
一开始wa了好几次,结果发现原来是check数组没有每次清空……
按理来讲应该wa一大片的吧,结果这都能有91分?
CPP#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m;
int head[101],total;
struct E
{
int to,inext;
}edge[30010];
void adde(int x,int y)
{
total++;
edge[total].to=y;
edge[total].inext=head[x];
head[x]=total;
}
int match[101];
bool check[101];
bool erfentu(int u)
{
for(int i=head[u];i;i=edge[i].inext)
{
int v=edge[i].to;
if(!check[v])
{
check[v]=true;
if(match[v]==-1 || erfentu(match[v]))
{
match[u]=v;
match[v]=u;
return true;
}
}
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin>>m>>n;
while(1)
{
int x,y;
cin>>x>>y;
if(x==-1 && y==-1) break;
adde(x,y);
adde(y,x);
}
memset(match,-1,sizeof(match));
int ans=0;
for(int i=1;i<=n;i++)
{
if(match[i]==-1)
{
memset(check,0,sizeof(check)); //没有加这句话都能有91分……
if(erfentu(i)) ans++;
}
}
if(ans==0) {cout<<"No Solution!"<<endl;return 0;}
cout<<ans<<endl;
for(int i=1;i<=m;i++)
{
if(match[i]==-1) continue;
cout<<i<<" "<<match[i]<<endl;
}
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...