zoukankan      html  css  js  c++  java
  • 1109. Conference

    1109. Conference

    Time limit: 0.5 second Memory limit: 64 MB
    On the upcoming conference were sent M representatives of country A and N representatives of country B (M and N ≤ 1000). The representatives were identified with 1, 2, …, M for country A and 1, 2, …, N for country B. Before the conference K pairs of representatives were chosen. Every such pair consists of one member of delegation Aand one of delegation B. If there exists a pair in which both member #i of A and member #j of B are included then #i and #j can negotiate. Everyone attending the conference was included in at least one pair. The CEO of the congress center wants to build direct telephone connections between the rooms of the delegates, so that everyone is connected with at least one representative of the other side, and every connection is made between people that can negotiate. The CEO also wants to minimize the amount of telephone connections. Write a program which given M, N, K and K pairs of representatives, finds the minimum number of needed connections.

    Input

    The first line of the input contains M, N and K. The following K lines contain the choosen pairs in the form of two integers p1 and p2, p1 is member of A and p2 is member of B.

    Output

    The output should contain the minimum number of needed telephone connections.

    Sample

    inputoutput
    3 2 4
    1 1
    2 1
    3 1
    3 2
    
    3
    Problem Source: Bulgarian National Olympiad Day #1
    ***************************************************************************************
    找最大匹配
    ***************************************************************************************
     1 #include<iostream>
     2 #include<string>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<cmath>
     6 #include<algorithm>
     7 using namespace std;
     8 int n,m,k;
     9 int s,t;
    10 int i,j;
    11 bool vis[1001];
    12 int link[1001];
    13 int map[1001][1001];
    14 bool  find(int x)//找增广路径
    15   {
    16       for(int is=1;is<=m;is++)
    17        {
    18            if(!vis[is]&&map[x][is])
    19              {
    20                  vis[is]=true;
    21                  if(link[is]==0||find(link[is]))//如果未被匹配,加入匹配
    22                    {
    23                        link[is]=x;
    24                        return true;
    25                    }
    26              }
    27        }
    28        return false;
    29   }
    30   int main()
    31   {
    32       cin>>n>>m>>k;
    33       memset(link,0,sizeof(link));
    34       memset(map,0,sizeof(map));
    35       for(i=1;i<=k;i++)
    36       {
    37           cin>>s>>t;
    38           map[s][t]=1;
    39       }
    40       int ans=0;
    41       for(i=1;i<=n;i++)
    42        {
    43            memset(vis,false,sizeof(vis));
    44            if(find(i))ans++;//最大匹配
    45        }
    46       cout<<n+m-ans<<endl;
    47       return 0;
    48 
    49   }
    View Code
  • 相关阅读:
    反射(8)程序集反射 Type 类
    反射(5)CLR 运行时探测程序集引用的步骤
    反射(1)程序集基础知识
    csc.exe(C# 编译器)
    证书(1)数字签名基础知识
    反射(7)动态程序集加载Load方法
    SignTool.exe(签名工具)
    反射(3)程序集加载 Assembly类
    关于卡巴斯基安全免疫区随笔
    文本提取工具 TextHelper
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3250544.html
Copyright © 2011-2022 走看看