• 【无聊放个模板系列】POJ 1274 (匈牙利)


     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<queue>
     7 #include<cmath>
     8 #include<stack>
     9 using namespace std;
    10 #define Maxn 210
    11 
    12 int match[Maxn];
    13 int n,m;
    14 
    15 struct node
    16 {
    17     int x,y,next;
    18 }t[Maxn*Maxn];int len;
    19 int first[Maxn];
    20 
    21 void ins(int x,int y)
    22 {
    23     t[++len].x=x;t[len].y=y;
    24     t[len].next=first[x];first[x]=len;
    25 }
    26 
    27 bool chw[Maxn];
    28 
    29 bool dfs(int x)
    30 {
    31     for(int i=first[x];i;i=t[i].next)
    32     {
    33         int y=t[i].y;
    34         if(chw[y]) continue;
    35         chw[y]=1;
    36         if(!match[y]||dfs(match[y]))
    37         {
    38             match[y]=x;
    39             return 1;
    40         }
    41     }
    42     return 0;
    43 }
    44 
    45 void ffind()
    46 {
    47     int ans=0;
    48     memset(match,0,sizeof(match));
    49     for(int i=1;i<=n;i++)
    50     {
    51         memset(chw,0,sizeof(chw));
    52         if(dfs(i)) ans++;
    53     }
    54     printf("%d
    ",ans);
    55 }
    56 
    57 int main()
    58 {
    59     while(scanf("%d%d",&n,&m)!=EOF)
    60     {
    61         len=0;
    62         memset(first,0,sizeof(first));
    63         for(int i=1;i<=n;i++)
    64         {
    65             int x;
    66             scanf("%d",&x);
    67             while(x--)
    68             {
    69                 int y;
    70                 scanf("%d",&y);
    71                 ins(i,y);
    72             }
    73         }
    74         ffind();
    75     }
    76     return 0;
    77 }

    2016-11-17 21:13:53

    匈牙利

  • 相关阅读:
    快速构建一个权限项目(七)
    快速构建一个权限项目(六)
    快速构建一个权限项目(五)
    快速构建一个权限项目(四)
    快速构建一个权限项目(三)
    快速构建一个权限项目(二)
    快速构建一个权限项目(一)
    MySql快速入门(四)
    Mysql快速入门(三)
    Mysql快速入门(二)
  • 原文地址:https://www.cnblogs.com/Konjakmoyu/p/6075520.html
Copyright © 2020-2023  润新知