90pts on #7输出只比答案少1
查看原帖
90pts on #7输出只比答案少1
1049051
JiuZhE66666楼主2023/12/16 16:44
#include<bits/stdc++.h>
using namespace std;
int atch[50005]={0};
int vis[50005]={0};
queue<int> G[505];
int weiy(int now)//让now在他的“仓库”里按顺序找下一个能连的右点,找得到返回1,找不到返回0
{
    while(!G[now].empty())//当仓库非空
    {
        int next=G[now].front();
        G[now].pop();
        if(atch[next]==0)//接下来分为三种情况,第一种,这个右点没人连,那我就直接连了
        {
            atch[next]=now;
            return 1;
        }
        else if(atch[next]!=0&&weiy(atch[next])==1)//第二种,这个点有人连,但是这个右点连接的左点可以滚蛋,即所连接的左点能不能找到下一个能连的右点。
        {
            atch[next]=now;
            return 1;
        }
        //这个右点现在连的左点动不得,我只能放弃。
    }
    return 0;//不return1就return0
}
int main()
{
    int n,m,e;
    cin>>n>>m>>e;
    for(int i=1;i<=e;i++)
    {
        int x,y;
        cin>>x>>y;
        G[x].push(y);
    }

    int ans=0;
    for(int i=1;i<=n;i++) ans+=weiy(i);//一个一个来
    cout<<ans;
    return 0;
}
2023/12/16 16:44
加载中...