poj3894 System Engineer 二分图匹配(匈牙利算法的DFS实现)
来源:互联网 发布:网络信息平台建设方案 编辑:程序博客网 时间:2024/05/22 02:15
System Engineer
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 491 Accepted: 208
Description
Bob is a skilled system engineer. He is always facing challenging problems, and now he must solve a new one. He has to handle a set of servers with differing capabilities available to process job requests from persistent sources - jobs that need to be processed over a long or indefinite period of time. A sequence of persistent job requests arrives revealing a subset of servers capable of servicing their request. A job is processed on a single server and a server processes only one job. Bob has to schedule the maximum number of jobs on the servers. For example, if there are 2 jobs j1, j2 and 2 servers s1, s2, job j1 requiring the server s1, and job j2 requiring also the server s1. In this case Bob can schedule only one job. Can you help him?
In the general case there are n jobs numbered from 0 to n-1, n servers numbered from n to 2*n-1, and a sequence of job requests. The problem asks to find the maximum number of jobs that can be processed.
In the general case there are n jobs numbered from 0 to n-1, n servers numbered from n to 2*n-1, and a sequence of job requests. The problem asks to find the maximum number of jobs that can be processed.
Input
The program input is at most 1 MB. Each data set in the file stands for a particular set of jobs. A data set starts with the number n (n <= 10000) of jobs, followed by the list of required servers for each job, in the format:jobnumber: (nr_servers) s1 ... snr_servers The program prints the maximum number of jobs that can be processed.
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
Output
For each set of data the program prints the result to the standard output from the beginning of a line.
Sample Input
2 0: (1) 2 1: (1) 2 1 0: (1) 1
Sample Output
11
Hint
There are two data sets. In the first case, the number of jobs n is 2, numbered 0 and 1. The sequence of requests for job 0 is: 0: (1) 2, meaning that job 0 requires 1 sever, the server numbered 2. The sequence of requests for job 1 is: 1: (1) 2, meaning that job 1 requires 1 sever, the server numbered 2. The result for the data set is the length of the maximum number of scheduled jobs, 1.
Source
Southeastern European Regional Programming Contest 2009
就是很水的二分图的匹配
用的模板,主要是内存分配要大一点,其次,不能用vector不是超时就是超内存,自已手写一个边表,模拟链表!
#include <iostream>#include <stdio.h>#include <vector>#include <string.h>using namespace std;/****************************************************二分图匹配(匈牙利算法的DFS实现)时间复杂度:O(VE);****************************************************/const int MAXN=10050;int uN,vN; int linker[MAXN];bool used[MAXN];struct systemtree{int s,next;}p[10*MAXN];//必须要有10万以上才行啊int start[MAXN];bool dfs(int u){ int i,v; for(i=start[u];i!=-1;i=p[i].next)//遍历u的所有相连的边{v=p[i].s;if(!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) { linker[v]=u; return true; } }} return false;}int hungary(){ int res=0; int u; memset(linker,-1,sizeof(linker)); for(u=0;u<uN;u++) { memset(used,0,sizeof(used)); if(dfs(u)) res++; } return res;}int main(){ int n,m,job,s,temp,num,i; while(scanf("%d",&n)!=EOF) { memset(start,-1,sizeof(start)); uN=vN=n;num=0; while(n--) { scanf("%d",&job); scanf(": (%d)",&m); temp=m;start[job]=num;//记录开始的起点p[num].s=-1;p[num].next=-1;//起点标记num++; while(temp--) { scanf("%d",&s);p[num].s=s-vN;//记录第一条边,化成从0开始p[num].next=num-1;//这个job的上一个结点,组成一个链表num++;//边的计数加一//p[job].push_back(s-vN); // g[s-vN]=job; }start[job]=num-1;//向前更新 } printf("%d\n",hungary()); } return 0;}
- poj3894 System Engineer 二分图匹配(匈牙利算法的DFS实现)
- poj 3894 System Engineer (二分图最大匹配--匈牙利算法)
- 二分图匹配(匈牙利算法DFS实现)
- ACM_模板_二分图匹配(匈牙利算法)-DFS
- 二分图最大匹配(匈牙利算法-DFS增广模板)
- 【二分图匹配】最大匹配-匈牙利算法BFS && DFS写法
- HDU 2063 二分匹配入门 匈牙利算法DFS实现
- 二分图的最大匹配、完美匹配和匈牙利DFS算法
- java实现二分图匹配匈牙利算法(HDU1083)
- HDU1803 Courses(二分图匹配,匈牙利算法,dfs)
- 二分图匹配匈牙利算法(DFS, BFS两种实现模板)
- (算法)二分图的最大匹配(匈牙利算法)
- 匈牙利算法 (二分图的最大匹配)
- [zz] 二分图匹配的匈牙利算法
- 二分图最大匹配的匈牙利算法
- 二分图最大匹配的匈牙利算法
- 二分图的最大匹配 (匈牙利算法)
- 二分图的最大匹配 匈牙利算法
- 【js学习笔记-010】--日期和时间
- NandFlash详述
- listView图片错乱
- Nginx 日志分析
- java设计模式---单例模式
- poj3894 System Engineer 二分图匹配(匈牙利算法的DFS实现)
- WPF中查找子控件、父控件的方法
- struts2如何访问action的特定方法
- 开源的物理引擎
- java POJO实现类比较器Comparable的排序规则
- 纪律:让“爱”变得愈发有力
- 自适应移动设备页面前端注意的问题
- 如何彻底卸载oracle
- Hibernate从入门到精通(六)一对一双向关联映射 .