zoukankan      html  css  js  c++  java
  • *HDU 1068 二分图

    Girls and Boys

    Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 10929    Accepted Submission(s): 5100


    Problem Description
    the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been “romantically involved”. The result of the program is the number of students in such a set.

    The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:

    the number of students
    the description of each student, in the following format
    student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
    or
    student_identifier:(0)

    The student_identifier is an integer number between 0 and n-1, for n subjects.
    For each given data set, the program should write to standard output a line containing the result.
     
    Sample Input
    7 0: (3) 4 5 6 1: (2) 4 6 2: (0) 3: (0) 4: (2) 0 1 5: (1) 0 6: (2) 0 1 3 0: (2) 1 2 1: (1) 0 2: (1) 0
     
    Sample Output
    5 2
     
    Source
     
    代码:
    找二分图最大独立集。题目中描述的是无向边。
    代码:
     1 // 模板 匈牙利算法dfs 最大独立集=总结点数-最大匹配(有向图);最大独立集=总结点数-最大匹配/2(无向图),(图中任意两个顶点都不相连的顶点集合。)
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstring>
     5 using namespace std;
     6 int mp[1003][1003],vis[1003],link[1003];
     7 int Mu,Mv,n;  //左集合点数,右集合点数,总点数
     8 int dfs(int x)      //找增广路。
     9 {
    10     for(int i=0;i<Mv;i++)
    11     {
    12         if(!vis[i]&&mp[x][i])
    13         {
    14             vis[i]=1;
    15             if(link[i]==-1||dfs(link[i]))
    16             {
    17                 link[i]=x;
    18                 return 1;
    19             }
    20         }
    21     }
    22     return 0;
    23 }
    24 int Maxcon()
    25 {
    26     int ans=0;
    27     memset(link,-1,sizeof(link));  
    28     for(int i=0;i<Mu;i++)
    29     {
    30         memset(vis,0,sizeof(vis));
    31         if(dfs(i)) ans++;
    32     }
    33     return ans;
    34 }
    35 int main()
    36 {
    37     int a,b,c;
    38     while(scanf("%d",&n)!=EOF)
    39     {
    40         memset(mp,0,sizeof(mp));
    41         for(int i=0;i<n;i++)
    42         {
    43             scanf("%d: (%d)",&a,&c);
    44             while(c--)
    45             {
    46                 scanf("%d",&b);
    47                 mp[a][b]=mp[b][a]=1;
    48             }
    49         }
    50         Mu=Mv=n;
    51         printf("%d
    ",n-Maxcon()/2);
    52     }
    53     return 0;
    54 }
  • 相关阅读:
    delete
    js混淆代码还原-js反混淆:利用js进行赋值实现
    Microservice Trade-Offs
    tagged by: microservices 【martinfowler.com】
    Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
    Why Can't I Access A Protected Member From A Derived Class
    tagged by: domain driven design 【martinfowler.com】
    Domain Driven Design
    Why Would I Ever Need to Use C# Nested Classes
    RabbitMQ compare with redis and MSMQ
  • 原文地址:https://www.cnblogs.com/--ZHIYUAN/p/6066555.html
Copyright © 2011-2022 走看看