2 条题解

  • 0
    @ 2026-7-12 10:32:31

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

      【参考程序】 //最大独立集=总数-最小覆盖集

      #include<bits/stdc++.h>
      using namespace std;
      struct edge{int x,y,pre;}a[1110000];int alen,last[11000];
      void ins(int x,int y){++alen;a[alen]=edge{x,y,last[x]};last[x]=alen;}
      int match[11100],chw[11100],tsp;
      bool findmuniu(int x)
      {
          for(int k=last[x];k>0;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 n1,n2,m;scanf("%d%d%d",&n1,&n2,&m);
          alen=0;memset(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<=n1;i++)
          {
              tsp=i;
              if(findmuniu(i)==1)ans++;
          }
          printf("%d",n1+n2-ans);
          return 0;
      }
      
      • 1

      *【二分图:最大独立集(难度:4)】二分图最大独立集元问题[scy]

      信息

      ID
      323
      时间
      2000ms
      内存
      128MiB
      难度
      3
      标签
      递交数
      53
      已通过
      28
      上传者