QOJ.ac

QOJ

시간 제한: 1.0 s 메모리 제한: 512 MB 총점: 100 난이도: [표시] 해킹 가능 ✓

#7528. 高效管理

통계

Ilona 是一家大型工业公司的首席执行官。该公司生产各种产品。对于每种产品,Ilona 都知道两个参数:销售一件该类产品的利润,以及生产一件该类产品的纯生产时间。某些产品的生产可能依赖于其他产品。例如,要制造一辆自行车,你需要制造车架和车轮;要制造车轮,你需要辐条和轮胎;对于车架和辐条,你需要加工过的金属。

Ilona 计划加速生产流水线,并按所需数量并行生产所有产品。在她的模型中,产品的实际生产时间等于该产品自身的纯生产时间与其所有依赖项(不仅是直接依赖项)的纯生产时间中的最大值。以自行车为例,其实际生产时间将是自行车、车架、车轮、辐条、轮胎和加工金属的纯生产时间中的最大值。

公司力求获得尽可能多的收益,因此 Ilona 请你列出所有具有“销售利润与实际生产时间之比”最大值的产品的编号。

输入格式

输入的第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示产品类型的数量。产品类型按 $1$ 到 $n$ 的整数编号。

第二行和第三行各包含 $n$ 个正整数。第二行中的第 $i$ 个整数是第 $i$ 种产品的销售利润,第三行中的第 $i$ 个整数是第 $i$ 种产品的纯生产时间。这些整数均不超过 $10^9$。

接下来 $n$ 行描述生产依赖关系。第 $i$ 行以整数 $m_i$ ($0 \le m_i < n$) 开头,表示第 $i$ 种产品的生产所依赖的产品类型数量。随后是 $m_i$ 个整数,描述这些依赖的产品类型。你可以假设所有 $m_i$ 的总和不超过 $10^5$。

你可以假设生产过程中不存在循环依赖,即没有任何类型可以直接或间接地依赖于自身。

输出格式

输出使销售利润与实际生产时间之比最大的产品类型的编号,每行输出一个编号。产品编号应按升序排列。

样例

输入 1

6
1 2 4 5 4 6
1 3 2 2 3 2
0
0
1 1
2 2 3
1 1
2 5 4

输出 1

3
6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.