2 条题解

  • 0
    @ 2025-10-8 16:57:14
    #include<bits/stdc++.h>
    using namespace std;
    const int N=110;
    vector<int>G[N];
    int match[N],chw[N],tps;
    bool fi(int x)
    {
        for(int y:G[x])
            if(chw[y]!=tps)
            {
                chw[y]=tps;
                if(match[y]==0||fi(match[y])==1)
                {
                    match[y]=x;
                    return 1;
                }
            }
        return 0;
    }
    int main()
    {
        int n,m,k;
        while(scanf("%d",&n)!=EOF && n)
        {
            scanf("%d%d",&m,&k);
            memset(G,0,sizeof(G));
            for(int i=1,x,y;i<=k;i++)
            {
                scanf("%d%d%d",&x,&x,&y);if(x==0 ||y==0)continue;
                x++,y++;
                G[x].emplace_back(y);
            }
            int ans=0;memset(match,0,sizeof(match));memset(chw,0,sizeof(chw));
            for(int i=1;i<=n;i++)
            {
                tps=i;
                if(fi(i))ans++;
            }
            printf("%d\n",ans);
        }
        return 0;
    }
    
    • 0
      @ 2025-10-8 16:57:08
      #include<bits/stdc++.h>
      using namespace std;
      const int N=110;
      vector<int>G[N];
      int match[N],chw[N],tps;
      bool fi(int x)
      {
          for(int y:G[x])
              if(chw[y]!=tps)
              {
                  chw[y]=tps;
                  if(match[y]==0||fi(match[y])==1)
                  {
                      match[y]=x;
                      return 1;
                  }
              }
          return 0;
      }
      int main()
      {
          int n,m,k;
      	while(scanf("%d",&n)!=EOF && n)
          {
              scanf("%d%d",&m,&k);
              memset(G,0,sizeof(G));
              for(int i=1,x,y;i<=k;i++)
              {
                  scanf("%d%d%d",&x,&x,&y);if(x==0 ||y==0)continue;
                  x++,y++;
                  G[x].emplace_back(y);
              }
              int ans=0;memset(match,0,sizeof(match));memset(chw,0,sizeof(chw));
              for(int i=1;i<=n;i++)
              {
                  tps=i;
                  if(fi(i))ans++;
              }
              printf("%d\n",ans);
      	}
          return 0;
      }
      • 1

      *【二分图:最小覆盖】机器任务[POJ1325]

      信息

      ID
      1465
      时间
      1000ms
      内存
      10MiB
      难度
      7
      标签
      递交数
      228
      已通过
      46
      上传者