1 条题解

  • 0
    @ 2025-10-8 16:49:24

    【参考程序】

    #include<bits/stdc++.h>
    using namespace std;
    struct edge{int x,y,pre;}a[30000];int alen,last[600];
    void ins(int x,int y){++alen;a[alen]=edge{x,y,last[x]};last[x]=alen;}
    int match[600],chw[600],tsp;
    bool findmuniu(int x)
    {
    	for(int k=last[x];k;k=a[k].pre)
    	{
    		int y=a[k].y;
    		if(chw[y]!=tsp)
    		{
    			chw[y]=tsp;
    			if(match[y]==0 || findmuniu(match[y])==1)
    			{
    				match[y]=x;
    				return 1; 
    			}
    		}
    	}
    	return 0;
    }
    int main() 
    {
        int n,m;scanf("%d%d",&n,&m);
        alen=0;sizeof(last,0,sizeof(last));
        for(int i=1;i<=m;i++)
        {
        	int x,y;scanf("%d%d",&x,&y);ins(x,y);
        }
        int ans=0;
        memset(match,0,sizeof(match));
        memset(chw,0,sizeof(chw));
        for(int i=1;i<=n;i++)
        {
        	tsp=i;
        	if(findmuniu(i)) ans++;
        }
        printf("%d\n",ans);
        return 0;
    }
    
    • 1

    *【二分图:最小覆盖】[USACO05NOV] Asteroids G

    信息

    ID
    320
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    124
    已通过
    46
    上传者