Firing
Time Limit: 5000MS   Memory Limit: 131072K
Total Submissions: 10696   Accepted: 3226

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.
 
题意:公司大裁员,希望尽可能的少裁剪员工,且裁掉以后所能获得的总利润最大化,输出裁剪的人数和获得的最大利润。裁员的时候裁掉某一个人,那么连同这个人的所有下属都将会被裁掉。

最大权闭合图的求解方法是

  1. 先构造网络流N,添加源点s,从s到正权值点做一条边,容量为点的权值。

  2. 添加汇点t,从负权值点到t做一条边,容量为点的权值的绝对值。

  3. 原来的边的容量统统设为无穷大。

  4. 求解最小割,最大权=正权值之和-最小割权值

  5. 残余网络中的点的个数即为裁员个数。

AC代码:

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int N_MAX = +, M_MAX = , V_MAX = N_MAX + ; typedef long long ll;
int n, m;
struct edge {
int to; ll cap;int rev;
edge(int to, ll cap, int rev) :to(to), cap(cap), rev(rev) {}
};
vector<edge>G[V_MAX];
int level[V_MAX];
int iter[V_MAX]; void add_edge(int from, int to, ll cap) {
G[from].push_back(edge(to, cap, G[to].size()));
G[to].push_back(edge(from, , G[from].size() - ));
} void bfs(int s) {
memset(level, -, sizeof(level));
queue<int>que;
level[s] = ;
que.push(s);
while (!que.empty()) {
int v = que.front(); que.pop();
for (int i = ; i < G[v].size(); i++) {
edge&e = G[v][i];
if (e.cap > && level[e.to] < ) {
level[e.to] = level[v] + ;
que.push(e.to);
}
}
}
} ll dfs(int v, int t, ll f) {
if (v == t)return f;
for (int &i = iter[v]; i < G[v].size(); i++) {
edge&e = G[v][i];
if (e.cap > && level[v] < level[e.to]) {
ll d = dfs(e.to, t, min(f, e.cap));
if (d > ) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return ;
} ll max_flow(int s, int t) {
ll flow = ;
for (;;) {
bfs(s);
if (level[t] < )return flow;
memset(iter, , sizeof(iter));
ll f;
while ((f = dfs(s, t, INT_MAX))>) {
flow += f;
}
}
} int res = ;
bool vis[V_MAX];
void solve(int v) {//深搜找点
res++;
vis[v] = true;
for (int i = ; i < G[v].size();i++) {
edge e = G[v][i];
if (e.cap > && !vis[e.to]) {
solve(e.to);
}
}
} int main() {
while (scanf("%d%d",&n,&m)!=EOF) {
res = ; memset(vis, , sizeof(vis));
int s = , t = n+,V=t+;
ll sum = ;
for (int i = ; i < n;i++) {
ll a;
scanf("%lld",&a);
if (a > ) { add_edge(s, i + , a); sum += a; }
else add_edge(i + , t, -a);
}
for (int i = ; i < m;i++) {
int a, b;
scanf("%d%d",&a,&b);
add_edge(a,b,INF);
}
ll flow=max_flow(s, t);
solve(s);
printf("%d %lld\n",--res,sum-flow);
for (int i = ; i < V;i++) {//向量清空
G[i].clear();
}
}
return ;
}

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 - [最大权闭合子图]

    题目链接:http://poj.org/problem?id=2987 Time Limit: 5000MS Memory Limit: 131072K Description You’ve fina ...

  3. POJ 2987 Firing 网络流 最大权闭合图

    http://poj.org/problem?id=2987 https://blog.csdn.net/u014686462/article/details/48533253 给一个闭合图,要求输出 ...

  4. POJ 2987 Firing(最大权闭合图)

    [题目链接] http://poj.org/problem?id=2987 [题目大意] 为了使得公司效率最高,因此需要进行裁员, 裁去不同的人员有不同的效率提升效果,当然也有可能是负的效果, 如果裁 ...

  5. POJ 2987 Firing 最大流 网络流 dinic 模板

    https://www.cnblogs.com/137shoebills/p/9100790.html http://poj.org/problem?id=2987 之前写过这道题,码一个dinic的 ...

  6. POJ 2987 Firing (最大权闭合图)

    Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 12108   Accepted: 3666 Descript ...

  7. POJ 2987 Firing(最大流最小割の最大权闭合图)

    Description You’ve finally got mad at “the world’s most stupid” employees of yours and decided to do ...

  8. POJ 2987 Firing【最大权闭合图-最小割】

    题意:给出一个有向图,选择一个点,则要选择它的可以到达的所有节点.选择每个点有各自的利益或损失.求最大化的利益,以及此时选择人数的最小值. 算法:构造源点s汇点t,从s到每个正数点建边,容量为利益.每 ...

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

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

随机推荐

  1. 如何写好一个vue组件,老夫的一年经验全在这了【转】 v-bind="$attrs" 和 v-on="$listeners"

    如何写好一个vue组件,老夫的一年经验全在这了 一个适用性良好的组件,一种是可配置项很多,另一种就是容易覆写,从而扩展功能 Vue 组件的 API 来自三部分——prop.事件和插槽: prop 允许 ...

  2. Navicat连接Oracle详细教程

    Navicat Premium算是比较好的一个可视化数据库管理工具了,短小精悍,一个工具解决三种数据库的连接问题,真正做到了集成管理,对MySQL,SQLServer而言,连接比较简单,就不赘述了,现 ...

  3. Java常见对象Object类中的个别方法

    Java常见对象Object类 public int hashCode() : 返回该对象的哈希码值. 注意:哈希值是根据哈希算法计算出来的一个值,这个值和地址值有关,但是不是实际地址值.你可以理解成 ...

  4. Ueditor1.4.3上传视频IE下无法播放的问题

    一:百度编辑器插入视频后,自动生成一段代码: <video class="edui-upload-video vjs-default-skin video-js" contr ...

  5. CS193p Lecture 8 - Protocols, Blocks and Animation

    一.协议(Protocols) 1. 声明协议 @protocol Foo <Xyzzy, NSObject> // ... @optinal // @required //... @en ...

  6. Java实现——字符串分割以及复制目录下的所有文件

    0.  前言 今天有个需求,把Android中data/data目录下指定(通过读预置的XML文件)的多个应用下的多个目录全部内容通过OTG模式复制到U盘中. 首先读取XML文件内的某个节点的属性值, ...

  7. Lambert (兰伯特)光照模型

    Lambert (兰伯特)光照模型 是光源照射到物体表面后,向四面八方反射,产生的漫反射效果.这是一种理想的漫反射光照模型.如下图:这个是顶点函数处理后的该光照模型,因此看起来像素不够平滑. 漫反射 ...

  8. Java-在JVM关闭前调用的函数

    参考:http://qtlkw.iteye.com/blog/1018872 package com.tj; import java.text.SimpleDateFormat; import jav ...

  9. [转]Python 之 使用 PIL 库做图像处理

    Python 之 使用 PIL 库做图像处理 1. 简介. 图像处理是一门应用非常广的技术,而拥有非常丰富第三方扩展库的 Python 当然不会错过这一门盛宴.PIL (Python Imaging ...

  10. WordPress 编辑器没有可视化

    第一次安装wordpress后出现文章编辑器只有一行按钮的问题,即使我安装了其他的编辑插件也是一样只有一行, 解决方法: 原来是再Users->All Users 中勾选了Disable the ...