zoukankan      html  css  js  c++  java
  • hdu1151

    题解:

    二分图边覆盖

    n-最大匹配

    代码:

    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    const int N=505;
    int fi[N],num,T,n,m,ne[N*N],zz[N*N],f[N],match[N],x,y;
    void jb(int x,int y)
    {
        ne[++num]=fi[x];
        fi[x]=num;
        zz[num]=y;
    }
    int dfs(int x)
    {
        for (int i=fi[x];i;i=ne[i])
         if (!f[zz[i]])
          {
              f[zz[i]]=1;
              if (!match[zz[i]]||dfs(match[zz[i]]))
               {
                   match[zz[i]]=x;
                   return 1;
               }
          }
        return 0;  
    }
    int main()
    {
        scanf("%d",&T);
        while (T--)
         {
             memset(match,0,sizeof match);
             memset(fi,0,sizeof fi);
             num=0;
             scanf("%d%d",&n,&m);
             while (m--)
              {
                  scanf("%d%d",&x,&y);
                  jb(x,y);
              }
             int ans=0;
            for (int i=1;i<=n;i++)
             {
                 memset(f,0,sizeof f);
                 ans+=dfs(i);
             } 
            printf("%d
    ",n-ans); 
         } 
    }
  • 相关阅读:
    属性选择器
    优先级
    hj_html&css
    hj_解决gpedit.msc不存在的问题
    hj_designPatterns
    hj_ssm
    hj-springmvc
    hj_mybatis
    hj_Python踩坑之旅
    hj_Python学习笔记
  • 原文地址:https://www.cnblogs.com/xuanyiming/p/8252896.html
Copyright © 2011-2022 走看看