poj 2987 Firing 最大权闭合图

【网络流】:poj2987,Firing 数学解释不多说了,参考:http://blog.csdn.net/scorpiocj/article/details/6085637 最大权闭合图,最大权=sum-最小割,sum为所有正点权的和;要裁掉几个人,根据最小割的性质,被裁掉的人肯定不在最小割中,所以只要从源点开始对残留网络进行遍历即可。 注意一点,sum类型为long long,否则出错。 /* * Dini 阅读详情

Firing
Time Limit: 5000MS Memory Limit: 131072K
Total Submissions: 7126 Accepted: 2164

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 ≤ i, j ≤ 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.

----------

最大权=正权和-最小割

从原点开始对残留网络dfs,能访问到的点裁去。

-----------

/*==============================================*\
 | Code Library
\*==============================================*/
/** head-file **/
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
/** define-for **/
#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for (int i=1;i<=int(n);++i)
#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)
#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)
#define REP_N(i, n) for (i=0;i<int(n);++i)
#define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)
#define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)
#define REP_1_N(i, n) for (i=1;i<=int(n);++i)
#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)
#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)
/** define-useful **/
#define clr(x,a) memset(x,a,sizeof(x))
#define sz(x) int(x.size())
#define see(x) cerr<<#x<<" "<<x<<endl
#define se(x) cerr<<" "<<x
#define pb push_back
#define mp make_pair
/** test **/
#define Display(A, n, m) {                      \
    REP(i, n){                                  \
        REP(j, m) cout << A[i][j] << " ";       \
        cout << endl;                           \
    }                                           \
}
#define Display_1(A, n, m) {                    \
    REP_1(i, n){                                \
        REP_1(j, m) cout << A[i][j] << " ";     \
        cout << endl;                           \
    }                                           \
}
using namespace std;
/** typedef **/
typedef long long LL;
/** Add - On **/
const int direct4[4][2]={ {0,1},{1,0},{0,-1},{-1,0} };
const int direct8[8][2]={ {0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1} };
const int direct3[6][3]={ {1,0,0},{0,1,0},{0,0,1},{-1,0,0},{0,-1,0},{0,0,-1} };
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long INFF = 1LL << 60;
const double EPS = 1e-9;
const double OO = 1e15;
const double PI = acos(-1.0); //M_PI;
const int maxn=11111;
const int maxm=1111111;
bool vis[maxn];
int cnt;
/*==============================================*\
 | Dinic最大流
 | INIT: prepare(n,S,T);addedge(u,v,c);节点0~n
 | CALL: Dinic_flow():int
\*==============================================*/
struct edgenode{
    int to;
    LL flow;
    int next;
};
struct Dinic{
    int node,src,dest,edge;
    int head[maxn],work[maxn],dis[maxn],q[maxn];
    edgenode edges[maxm];
    void prepare(int _node,int _src,int _dest){
        node=_node,src=_src,dest=_dest;
        memset(head,-1,sizeof(head));
        edge=0;
    }
    void addedge(int u,int v,LL c){
        edges[edge].flow=c,edges[edge].to=v,edges[edge].next=head[u],head[u]=edge++;
        edges[edge].flow=0,edges[edge].to=u,edges[edge].next=head[v],head[v]=edge++;
    }
    bool Dinic_bfs(){
        int i,u,v,l,r=0;
        for (i=0; i<node; i++) dis[i]=-1;
        dis[q[r++]=src]=0;
        for (l=0; l<r; l++){
            for (i=head[u=q[l]]; i!=-1; i=edges[i].next){
                if (edges[i].flow&&dis[v=edges[i].to]<0){
                    dis[q[r++]=v]=dis[u]+1;
                    if (v==dest) return true;
                }
            }
        }
        return false;
    }
    LL Dinic_dfs(int u,LL exp){
        if (u==dest) return exp;
        int v;
        LL tmp;
        for (int &i=work[u]; i!=-1; i=edges[i].next){
            if (edges[i].flow&&dis[v=edges[i].to]==dis[u]+1&&
                (tmp=Dinic_dfs(v,min(exp,edges[i].flow)))>0){
                edges[i].flow-=tmp;
                edges[i^1].flow+=tmp;
                return tmp;
            }
        }
        return 0;
    }
    LL Dinic_flow(){
        int i;
        LL ret=0,delta;
        while (Dinic_bfs()){
            for (i=0;i<node;i++) work[i]=head[i];
            while (delta=Dinic_dfs(src,INFF)) ret+=delta;
        }
        return ret;
    }
    void dfs(int u){
        vis[u]=true;
        for (int i=head[u];i!=-1;i=edges[i].next){
            int v=edges[i].to;
            if (vis[v]) continue;
            if (edges[i].flow>0){
                dfs(v);
                cnt++;
            }
        }
    }
}solver;

int n,m;
LL b[maxn];

LL sum;
int main()
{
    while (~scanf("%d%d",&n,&m))
    {
        clr(vis,0);
        sum=0;
        solver.prepare(n+2,0,n+1);
        REP_1(i,n){
            scanf("%I64d",&b[i]);
            if (b[i]>0) sum+=b[i];
            if (b[i]>0) solver.addedge(0,i,b[i]);
            if (b[i]<0) solver.addedge(i,n+1,-b[i]);
        }
        REP(i,m){
            int x,y;
            scanf("%d%d",&x,&y);
            solver.addedge(x,y,INFF);
        }
        LL ans=sum-solver.Dinic_flow();
        cnt=0;
        solver.dfs(0);
        printf("%d ",cnt);
        printf("%I64d\n",ans);
    }
    return 0;
}




openEuler服务器离线安装实战:从Docker到Samba的完整避坑指南 本文提供了一份详尽的openEuler服务器离线部署实战指南,重点解决了在无网络环境下安装Docker、Samba等软件的依赖难题。文章深入对比了`dnf install`、`rpm`直接安装及禁用仓库安装三种核心方法,并分享了构建本地DNF仓库的进阶策略,旨在帮助运维人员构建高效可靠的离线部署工作流。 阅读详情

相关推荐

动力电池BMS功能安全实战:从ISO 26262标准到软硬件设计落地

功能安全是确保电子电气系统在发生故障时仍能维持安全状态的核心工程理念,其核心原理是通过系统化的危害分析、风险评估和故障容错设计,将风险降至合理可行的最低水平。这一理念在汽车电子领域的技术价值尤为突出,它通过ISO 26262等标准,将抽象的安全要求转化为可量化、可验证的工程实践。在新能源汽车三电系统中,电池管理系统(BMS)作为守护电池安全的关键控制器,其功能安全实现直接关系到高压安全和整车安全。具体应用场景涵盖从芯片选型、硬件冗余设计到基于AUTOSAR的软件架构与安全机制。本文聚焦于动力电池BMS,深入

weixin_29172201的博客 333

POJ2987-Firing

利用Dinic求最小割,求最大权闭合图。 其中最大权=正权和-最小割,即最大裁员收益。 在求出最小割之后,遍历搜索残余网络的顶点个数即可求出裁员的个数。数据太大需要用long long。 计算残余网络的顶点个数时要去掉源点。#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <algo

Collider 417

在thinkBook16的win11基础上安装ubuntu22.04

背景:联想ThinkBook16 pro 32G/512G,系统盘已安装Win11,加装一条M.2-2T固态,想在2T上分一个300GB的EXT4分区,然后把ubuntu22.04安装在该分区上,并实现Win11+Linux多系统共存。 目标:实现多磁盘下分区管理的简化,优化掉一些不必要的多余的维护性质的分区。

QzmAIoT 4009

poj 2987(Firing)

题目链接:http://poj.org/problem?id=2987 题意简述:一个公司要裁人,给出裁每个人都有个盈利或者损失,如果一个人的上司被裁那么他也将被裁,现在问怎样裁才能使得公司的收益最大,最大为多少? 分析:因为这里上司和下属之间存在一个依赖关系,下属存

552

Arcgis 10.3 与 ArcGIS Engine 10.3 安装与破解

Arcgis 10.3 与 ArcGIS Engine 10.3 安装与破解

weixin_52127098的博客 4744

NVIDIA Jetson Orin DLA架构解析与AI推理优化实践

深度学习加速器(DLA)作为专用AI推理芯片,通过固定功能架构实现卷积、池化等神经网络操作的高效能比处理。其核心原理在于硬件级优化计算单元与数据流,相比通用GPU可提升3-5倍能效。在边缘计算场景中,DLA与GPU的异构协同成为关键,特别适合自动驾驶感知、机器人视觉等实时性要求高的应用。NVIDIA Jetson Orin平台通过结构化稀疏技术,在ResNet50等模型上实现近2倍性能提升。开发实践中需注意算子支持、精度校准等关键点,结合TensorRT工具链可充分发挥DLA在低功耗场景的独特优势。

weixin_32999557的博客 408

poj2987--Firing(最大权闭合图)

poj2987:题目链接 题目大意:有个公司,n个员工,m个关系,因为亏损,所以要辞退一些员工,给出辞退每个员工会给带来的收益(有正有负),关系x y代表x是y的上司,如果辞退一个上司,那么他手下的人都会退出,问最大的收益,和要删除的人数。 因为删掉一个上司,员工也会离开,所以最后求的删除的人会是一个闭合图,也就是求最大权闭合图,将其中正值k的点i连接边值为正,原图中的边值为正无穷,负值k的点

随风的专栏 1575

SAP 的预算控制并非单一功能,而是根据管控的精细度和业务场景,主要通过三个模块实现:CO(成本控制)、FM(基金管理) 和 PS(项目系统)

SAP系统提供三种预算控制模型:基于CO模块的成本中心/内部订单预算管控,适用于日常费用管理;基于FM模块的基金中心/承诺项目预算控制,满足公共部门严格资金管理需求;基于PS模块的WBS元素预算控制,专为项目型企业设计。各模型通过特定配置实现预算编制、审批、控制和分析功能,并配有核心事务代码(T-Code)支持全流程操作。企业可根据业务场景选择适合的预算控制方式,实现从预算编制到执行监控的闭环管理。

金牌架构师 267

POJ 2987: Firing

题目链接: http://poj.org/problem?id=2987 题意: 现在有一群人,开除每个人都会有一个相应的收益(可正可负)。 另给出他们之间的上下级关系,如果开除一个人就必须开除他的下属,以及他下属的下属,依次类推…… 求开除他们中一部分人所能获得的最大收益。 算法: 最大权闭合子图。 Amber的《最小割模型在信息学竞赛中的应用》里面已经讲解的非常

frog的小池塘 1006

使用OpenSSL创建多级CA证书链签发证书并导出为pkcs12/p12/pfx文件

文章目录1. 生成根CA证书并自签2. 生成二级CA证书并使用CA证书签发3. 生成服务器证书并使用二级CA证书签发4. 制作CA证书链5. 打包为p12文件6. 注意事项7. 使用`openssl x509`和`openssl ca`签发CA证书的差别 操作步骤: 生成根CA证书并自签 生成二级CA证书并使用CA证书签发 生成服务器证书并使用二级CA证书签发 制作CA证书链 打包为p12文件 1. 生成根CA证书并自签 # 创建root-ca并自签名 openssl req -x509 -newkey

Laurence的技术博客 9579

【系统分析师】高分论文:论基于构件的软件开发(气象灾害影响评估系统)

本文以某手机气象灾害影响评估系统为例,探讨了基于构件技术的软件开发实践。通过分析开发中常见的功能模块重复问题,提出建立企业构件库、针对性选择构件和加强构件管理的解决方案。项目实施中成功复用登录模块等通用构件,并针对气象数据转换需求开发新构件,最终在8个月内高质量完成系统建设。文章总结了构件开发的三个关键点:构件库建设是基础、构件选择需精准、构件管理要规范。同时指出需注意全新需求开发、性能优化等问题,建议通过培训提升团队对构件的理解力。该案例证明构件技术能有效缩短周期、降低成本,为企业积累可复用的技术资产。

数据知道的博客 4256

POJ2987 Firing 最大权闭合图

题意不难。 思路很容易想到用网络流的模型。把那些关联关系用单向边来连接,但是没想好是怎么处理出最优解。 都说用最大权闭合图。查了一下相关内容。 我的理解是:其实也是流网络的应用。特殊的地方在于每个点的权值的转化: 权值为正的接连源点S,权值为负的连接汇点T。中间的

Aszxqw 1388

【openwrt-21.02】T750 openwrt 双系统说明及切换方法

高度集成的 T750 平台大幅减少组件数量,为产品设计者提供更小的尺寸和更低的功耗。T750 采用先进的 7nm 制程,高度集成 5G 调制解调器和四核 Arm CPU,提供较强的功能和配置,设备制造商得以打造精巧的高性能 CPE 产品,如固定无线接入(FWA)路由器和移动热点。3. preloader 加载并启动 A 系统,若 A 系统的任一启动阶段加载失败,preloader 将重新加载并启动 A 系统 3 次,若 3 次均失败,则自动切换至 B 系统,加载并启动 B 系统。A/B 系统切换流程如下。

wgl307293845的博客 1427

POJ2987 Firing 【最大权闭合图】

POJ2987 Firing 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 “Do...

Dream_maker的博客 373

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Firing POJ - 2987(最大权闭合图)

Firing POJ - 2987 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?”,

rainbowsea_1的博客 410

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POJ2987-Firing(最大权闭合图)

Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 10904   Accepted: 3290 Description You’ve finally got mad at “the world’s most stupid” employees

wang_128的博客 477

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

poj 2987 Firing(最大权闭合图)

Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 6198   Accepted: 1875 Description You’ve finally got mad at “the world’s most stupid” employees of

志当存高远 1086

POJ 2987 Firing (最大权闭合图)

Firing Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 6666 Accepted: 2020 Description You’ve finally got mad at “the world’s most stupid” employees of your

GentleH's 484

POJ - 2987 Firing(最大权闭合图)

题目链接:点击查看 题目大意:某公司想要裁员,裁员的标准是如果某人被裁,那么其下属也会被裁,依此类推,每一个人都有一个贡献度,问怎样裁员才能使得最后的贡献度最大并且裁掉人数最少 题目分析:最大权闭合图的模板题,先插个眼: 大佬的博客 简单背一下结论吧: 最大权闭合图 :原边改为正无穷后,添加S和T,S向所有点连正权,所有点向T连负权的绝对值.求最小割,用所有权值为正的点相加之和减掉最小割...

Falcon的博客 390

POJ 2987 Firing 【最大权闭合图】

POJ 2987 题目链接   题意: 公司要进行裁员,裁掉一个人可以获得一定的利益或损失(用正数和负数表示)。 一些人之间有附属关系,比如b是a的下属,则裁掉a就必须裁掉b。 问要取得最大的利益,最少要裁掉几个人,取得的最大利益是多少 结论一:最大权闭合图的的权=原图中权值为正的点的和 - 最小割(最大流) 结论二:最小割对应取点方案就是最小取点数 具体详细证

tystrwor的博客 344

POJ 2987 Firing 最大权闭合图

点击打开链接 Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 7976   Accepted: 2409 Description You’ve finally got mad at “the world’s mo

代码改变世界,keep coding。 1340

poj2987 Firing 最大权闭合图

题意:

AC_kereo的专栏 849

Firing (poj 2987 最大权闭合图)

题意:公司有n个员工和m个从属关系,现在要辞退一些人,每辞退一个人 i 会到一个价值wi(正或者负),辞退一个人也要连同他的下属一起辞退,问能得到的最大收益是多少且最少的辞退人数是多少。 思路:最大权闭合图,关键是求最少的辞退人数,这里就为最小割的取点数,具体证明看这位大神吧点击打开链接 另外注意要用long long

@you! 820

poj 2987 Firing 最大权闭合图

题目链接:http://poj.org/problem?id=2987 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...

weixin_30686845的博客 83
上一篇: Poj 3713 Transferring Sylla 3-连通
下一篇: POJ 2914 Minimum Cut 无向图最小割
cyendra
博客等级 码龄14年 191粉丝 462原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值