1109. Conference
2013-08-10 20:11
323 查看
1109. Conference
Time limit: 0.5 second Memory limit: 64 MBOn 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
input | output |
---|---|
3 2 4 1 1 2 1 3 1 3 2 | 3 |
***************************************************************************************
找最大匹配
***************************************************************************************
#include<iostream> #include<string> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int n,m,k; int s,t; int i,j; bool vis[1001]; int link[1001]; int map[1001][1001]; bool find(int x)//找增广路径 { for(int is=1;is<=m;is++) { if(!vis[is]&&map[x][is]) { vis[is]=true; if(link[is]==0||find(link[is]))//如果未被匹配,加入匹配 { link[is]=x; return true; } } } return false; } int main() { cin>>n>>m>>k; memset(link,0,sizeof(link)); memset(map,0,sizeof(map)); for(i=1;i<=k;i++) { cin>>s>>t; map[s][t]=1; } int ans=0; for(i=1;i<=n;i++) { memset(vis,false,sizeof(vis)); if(find(i))ans++;//最大匹配 } cout<<n+m-ans<<endl; return 0; }
View Code
相关文章推荐
- Ural1109 Conference(二分图匹配)
- 【图论】【二分图匹配】[Ural 1109]Conference
- Ural1109_Conference(二分图最大匹配/匈牙利算法/网络最大流)
- Ural-1109-Conference
- timus 1109 Conference(二分图匹配)
- 1109. Conference
- ural 1109 Conference (二分图匹配)
- Ural 1109 Conference(最小路径覆盖数)
- 1109. Conference(二分图)
- Ural 1109 Conference(匈牙利算法·转换)
- Ural1109_Conference(二分图最大匹配/匈牙利算法/网络最大流)
- Office Developers Conference 2006 召开中
- ERE Global Conference 2007 (Amsterdam)
- Area Sort by area Conference Name, Home page,Where & When Sort by conference, Latest deadline Sort by deadline
- Top tier conferences & journals in Computer Science Area
- [1109模拟]
- Computer Security Conference Ranking and Statistic 计算机安全会议排名和统计
- Computer Science Conference Rankings
- Computer Vision Conference
- 计算机视觉、人工智能、数据挖掘顶级会议(Computer Version & AI & Data Mining Top Conference)