题目链接:http://poj.org/problem?id=2987

Time Limit: 5000MS Memory Limit: 131072K

Description

You’ve finally got mad at “the world’s most stupid” employees of yours and decided to do some firings. You’re now simply too mad to give response to questions like “Don’t you think it is an even more stupid decision to have signed them?”, yet calm enough to consider the potential profit and loss from firing a good portion of them. While getting rid of an employee will save your wage and bonus expenditure on him, termination of a contract before expiration costs you funds for compensation. If you fire an employee, you also fire all his underlings and the underlings of his underlings and those underlings’ underlings’ underlings… An employee may serve in several departments and his (direct or indirect) underlings in one department may be his boss in another department. Is your firing plan ready now?

Input

The input starts with two integers n (0 < n ≤ 5000) and m (0 ≤ m ≤ 60000) on the same line. Next follows n + m lines. The first n lines of these give the net profit/loss from firing the i-th employee individually bi (|bi| ≤ 107, 1 ≤ i ≤ n). The remaining m lines each contain two integers i and j (1 ≤ ij ≤ n) meaning the i-th employee has the j-th employee as his direct underling.

Output

Output two integers separated by a single space: the minimum number of employees to fire to achieve the maximum profit, and the maximum profit.

Sample Input

5 5
8
-9
-20
12
-10
1 2
2 5
1 4
3 4
4 5

Sample Output

2 2

Hint

As of the situation described by the sample input, firing employees 4 and 5 will produce a net profit of 2, which is maximum.

题意:

题目给出N个人,M个直属关系;

N个人每个人都有一个“解雇收益值”,代表公司解雇这个人收益为多少(为负就代表损失);

M个直属关系:(u, v)代表了,解雇u则必须解雇v;

求公司最少解雇几个人之后,可获得最大收益,为多少;

题解:

显然解雇的人满足闭合图关系,而受益最大则是要求最大点权,故本题就是一个最大权闭合子图;

参考http://www.cnblogs.com/dilthey/p/7565206.html即可。

当然,怎么求出被炒的人呢?

在跑完最大流后,残量网络中超级源点s到与其直接相连的点中:

  如果这条边不满流,就属于图S(分割后的两个图中包含超级源点s的那个图),则是属于被解雇的人,就标记;

  如果这条边满流,就属于割集,则这条边的终点不是解雇的人;

然后剩下的,由于图S中,除了与s相连的边权值不为INF外,其他必然为INF,必然不满流,而如果走到了连接t的边,又会变成满流,就会的停下来;

所以只要按着满流与否的条件,DFS下去,不断标记不满流边的终点即可。

AC代码:

 #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define MAXN 5005
#define MAXM 60005
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,m;
ll sum;
int cnt;
struct Edge{
int u,v;
ll c,f;
};
struct Dinic
{
int s,t;
vector<Edge> E;
vector<int> G[MAXN];
bool vis[MAXN];
int lev[MAXN];
int cur[MAXN];
void init(int l,int r)
{
E.clear();
for(int i=l;i<=r;i++) G[i].clear();
}
void addedge(int from,int to,ll cap)
{
E.push_back((Edge){from,to,cap,});
E.push_back((Edge){to,from,,});
int m=E.size();
G[from].push_back(m-);
G[to].push_back(m-);
}
bool bfs()
{
memset(vis,,sizeof(vis));
queue<int> q;
q.push(s);
lev[s]=;
vis[s]=;
while(!q.empty())
{
int now=q.front(); q.pop();
for(int i=,_size=G[now].size();i<_size;i++)
{
Edge edge=E[G[now][i]];
int nex=edge.v;
if(!vis[nex] && edge.c>edge.f)
{
lev[nex]=lev[now]+;
q.push(nex);
vis[nex]=;
}
}
}
return vis[t];
}
ll dfs(int now,ll aug)
{
if(now==t || aug==) return aug;
ll flow=,f;
for(int& i=cur[now],_size=G[now].size();i<_size;i++)
{
Edge& edge=E[G[now][i]];
int nex=edge.v;
if(lev[now]+ == lev[nex] && (f=dfs(nex,min(aug,edge.c-edge.f)))>)
{
edge.f+=f;
E[G[now][i]^].f-=f;
flow+=f;
aug-=f;
if(aug==) break;
}
}
return flow;
}
ll maxflow()
{
ll flow=;
while(bfs())
{
memset(cur,,sizeof(cur));
flow+=dfs(s,INF);
}
return flow;
}
}dinic; bool vis[MAXN];
void dfs(int u)
{
for(int i=,_size=dinic.G[u].size();i<_size;i++)
{
Edge& e=dinic.E[dinic.G[u][i]];
if(!vis[e.v] && e.c>e.f)
{
vis[e.v]=;
dfs(e.v);
}
}
}
int main()
{
scanf("%d%d",&n,&m);
sum=;
dinic.init(,n+);
dinic.s=, dinic.t=n+;
for(int i=,w;i<=n;i++)
{
scanf("%d",&w);
if(w>)
{
sum+=(ll)w;
dinic.addedge(dinic.s,i,w);
}
else if(w<) dinic.addedge(i,dinic.t,-w);
}
for(int i=,u,v;i<=m;i++)
{
scanf("%d%d",&u,&v);
dinic.addedge(u,v,INF);
}
//建图完毕
ll max_flow=dinic.maxflow();
//计算出最大流,同时得到残存网络 memset(vis,,sizeof(vis));
dfs(dinic.s);//遍历残存网络,找出被解雇的人
cnt=;
for(int i=;i<=n;i++) if(vis[i]) cnt++; printf("%d %I64d\n",cnt,sum-max_flow);
}

POJ 2987 - Firing - [最大权闭合子图]的更多相关文章

  1. poj 2987 Firing 最大权闭合图

    题目链接:http://poj.org/problem?id=2987 You’ve finally got mad at “the world’s most stupid” employees of ...

  2. POJ 2987 Firing | 最大权闭合团

    一个点带权的图,有一些指向关系,删掉一个点他指向的点也不能留下,问子图最大权值 题解: 这是最大权闭合团问题 闭合团:集合内所有点出边指向的点都在集合内 构图方法 1.S到权值为正的点,容量为权值 2 ...

  3. poj2987 Firing 最大权闭合子图 边权有正有负

    /** 题目:poj2987 Firing 最大权闭合子图 边权有正有负 链接:http://poj.org/problem?id=2987 题意:由于金融危机,公司要裁员,如果裁了员工x,那么x的下 ...

  4. 【POJ 2987】Firing (最小割-最大权闭合子图)

    裁员 [问题描述] 在一个公司里,老板发现,手下的员工很多都不务正业,真正干事员工的没几个,于是老板决定大裁员,每开除一个人,同时要将其下属一并开除,如果该下属还有下属,照斩不误.给出每个人的贡献值和 ...

  5. poj 2987 Firing【最大权闭合子图+玄学计数 || BFS】

    玄学计数 LYY Orz 第一次见这种神奇的计数方式,乍一看非常不靠谱但是仔细想想还卡不掉 就是把在建图的时候把正权变成w*10000-1,负权变成w*10000+1,跑最大权闭合子图.后面的1作用是 ...

  6. 2018.06.27Firing(最大权闭合子图)

    Firing Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 11558 Accepted: 3494 Description ...

  7. BZOJ1565 [NOI2009]植物大战僵尸(拓扑排序 + 最大权闭合子图)

    题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=1565 Description Input Output 仅包含一个整数,表示可以 ...

  8. HDU 3879 Base Station(最大权闭合子图)

    经典例题,好像说可以转化成maxflow(n,n+m),暂时只可以勉强理解maxflow(n+m,n+m)的做法. 题意:输入n个点,m条边的无向图.点权为负,边权为正,点权为代价,边权为获益,输出最 ...

  9. [BZOJ 1497][NOI 2006]最大获利(最大权闭合子图)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1497 分析: 这是在有向图中的问题,且边依赖于点,有向图中存在点.边之间的依赖关系可以 ...

随机推荐

  1. nuget包循环引用问题

    1.项目中有类库YesWay.Nlog.RabbitMQ,依赖项如下YesWay.Nlog.RabbitMQ=>YesWay.Service.Discovery=>YesWay.Log 2 ...

  2. Hightchart 技巧

    http://blog.csdn.net/u014796515/article/details/24428131

  3. Linux 常用文件

    /etc/exports /etc/services /etc/sysctl.conf /etc/logrotate.conf /etc/docker/key.json /etc/docker/dae ...

  4. 高并发应对:淘宝CDN缓存服务器部署探秘

    转自:http://server.chinabyte.com/6/12663506.shtml “好,时间到,开抢!”坐在电脑前早已等待多时的宋兰(化名)一看时间已到2011年11月11日零时,便迫不 ...

  5. C语言从零开始(十四)-字符串处理

    在软件开发过程中,字符串的操作相当频繁.在标准C语言库中提供了很多字符串处理的函数.今天我们来介绍一些常用的字符串处理函数.1. 字符串输入输出1.1 printf() scanf() 之前我们学习过 ...

  6. 常见C语言编译错误解析【转】

    C语言编译错误信息及说明1. 在函数 ‘transform’ 中:7: 错误:expected ‘;’ before ‘{’ token    解释:‘{’之前的某个语句缺少分号‘;’: 2. 在函数 ...

  7. 【转载】.NET中锁6大处理方法 悲观乐观自己掌握

    我们为什么需要锁? 在多用户环境中,在同一时间可能会有多个用户更新相同的记录,这就会产生冲突,这个就是著名的并发性问题. 图 1 并行性问题漫画 如何解决并发性问题? 借助正确的锁定策略可以解决并发性 ...

  8. 开始使用ARC

    Automatic Reference Counting (ARC)是编译器自动管理Objective-C对象的一个功能,相对于不得不考虑retain和release操作来说,ARC让我们有更多的精力 ...

  9. 对 Sea.js 进行配置 seajs.config

    配置 可以对 Sea.js 进行配置,让模块编写.开发调试更方便. seajs.config seajs.config(options) 用来进行配置的方法. seajs.config({ // 别名 ...

  10. Esper学习之一:Esper介绍

    CEP即Complex Event Process,中文意思就是“复杂事件处理”.听起来好像很复杂,实际上就是基于事件流进行数据处理,把要分析的数据抽象成事件,然后将数据发送到CEP引擎,引擎就会根据 ...