当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2987:Firing

题目描述

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?

输入解释

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 ≤ in). The remaining m lines each contain two integers i and j (1 ≤ i, jn) meaning the i-th employee has the j-th employee as his direct underling.

输出解释

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

输入样例
5 5
8
-9
-20
12
-10
1 2
2 5
1 4
3 4
4 5
输出样例
2 2
提示
As of the situation described by the sample input, firing employees 4 and 5 will produce a net profit of 2, which is maximum.

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2987

最后修改于 2020-10-29T06:49:12+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000 131072