题解
二分图匹配,总的来说就是如果我的位子没人霸占,那我就坐,如果没人霸占,那我尝试着让他滚蛋
如果一个位子经历过两次滚蛋,说明别人确实没位子坐了,人家确实需要这个位子,那我就换一个位子
code
#include<bits/stdc++.h>
using namespace std;
int belong[205]={0};
int vis[205]={0};
vector<int> G[205];
int ss(int now)//这个函数的定义为搜索当前节点能否找到归属
{
for(auto to:G[now]) if((!belong[to]||(!vis[to]&&(vis[to]=1)&&ss(belong[to])))&&(belong[to]=now)) return 1;//用&&完成赋值
//如果这个点没有被滚蛋过,那就访问这个点,让他滚蛋,或者是这个点还没有人踏足过
return 0;
}
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
int k;
cin>>k;
while(k--)
{
int x;
cin>>x;
G[i].push_back(x);
}
}
int sum=0;
for(int i=1;i<=n;i++)
{
memset(vis,0,sizeof vis);//记录牛棚的访问情况,如果塞入当前节点的时候牛棚访问超过两次,说明出现循环调用,而这时调用这个点的可以是任何点
sum+=ss(i);
}
cout<<sum<<endl;
return 0;
}
标签:Perfect,滚蛋,int,P1894,belong,vis,Stall,位子,&&
From: https://www.cnblogs.com/pure4knowledge/p/18057627