zoukankan      html  css  js  c++  java
  • POJ3041:Asteroids【二分图匹配】

    二分图的最大匹配=最小顶点覆盖(Konig定理)=最大独立集的补集最大匹配经典的三种模型  这题就是最小顶点覆盖,顺便这题留给我的经验就是调试的时候一定要细心细心再细心对模板的各个细节都要熟!!

    #include<cstdio>

    #include<string.h>

    #include<iostream>

    using namespace std;

    const int maxn=10005;

    intn,map[maxn][maxn]={{0}},match[maxn]={0},visit[maxn]={0},x,y,ans=0,k;

    int dfs(int t)

    {

       for (int i=1;i<=n;i++)if (map[t][i]==1 && visit[i]==0)

        {

           visit[i]=1;

           if (match[i]==-1 ||dfs(match[i])==1)

           {

               match[i]=t;

               return 1;

           }

        }

       return 0;

    }

    int main()

    {

       scanf("%d%d",&n,&k);

       for(int i=1;i<=k;i++)

        {

           scanf("%d%d",&x,&y);

           map[x][y]=1;

        }

       memset(match,255,sizeof(match));

       for(int i=1;i<=n;i++)

        {

               memset(visit,0,sizeof(visit));

               if (dfs(i)==1)ans++;

        }

       printf("%d ",ans);

       return 0;

    }

  • 相关阅读:
    性能测试系列七 工具选择
    Selenium Web自动化面试题总结(下篇)
    性能测试系列六 评估压测量
    hexo 安装
    光纤收发器组网方式
    频谱仪
    交换机网管telent
    区块链共识机制
    SDH、MSTP、OTN和PTN
    ACL知识
  • 原文地址:https://www.cnblogs.com/philippica/p/4006963.html
Copyright © 2011-2022 走看看