QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#1291. 脱欧谈判

Statistics

众所周知,英国脱欧谈判正在进行中,但我们仍不知道它们是否能按时完成。

谈判将按主题逐一进行。为了以最有效的方式组织谈判,所有主题都将在单独的会议中讨论并最终确定,每次会议讨论一个主题。

这种制度的部分原因在于某些主题之间存在(非循环的)依赖关系:例如,在决定关税之前,无法就关税同盟进行有意义的讨论。欧盟可以决定谈判主题的任何顺序,只要遵守上述依赖关系并涵盖所有主题即可。

每个主题都将利用所有可用的数据进行详尽讨论,包括过去会议的关键结论。在每次会议开始时,代表们将为到那时为止已经进行过的每一场会议(即使是无关的会议)额外花费一分钟,以回顾讨论内容并理解其结论是如何得出的。参见图 B.1 中的示例。

没有人喜欢冗长的会议。欧盟希望你帮助安排会议顺序,使得最长的那场会议耗时尽可能短。

图 B.1:样例输入 2 的一种解决方案中,每场会议耗时情况的说明。

输入格式

输入包含: 一行包含一个整数 $n$ ($1 \le n \le 4 \cdot 10^5$),表示要讨论的主题数量。主题编号为 $1$ 到 $n$。 $n$ 行,描述谈判主题。第 $i$ 行以两个整数 $e_i$ 和 $d_i$ ($1 \le e_i \le 10^6, 0 \le d_i < n$) 开头,分别表示就主题 $i$ 达成结论所需的分钟数,以及在讨论主题 $i$ 之前必须先处理的其他特定主题的数量。 * 该行的其余部分包含 $d_i$ 个不同的整数 $b_{i,1}, \dots, b_{i,d_i}$ ($1 \le b_{i,j} \le n$ 且对于每个 $j$,$b_{i,j} \neq i$),即在讨论主题 $i$ 之前需要完成的主题列表。

保证主题依赖关系中不存在循环,且所有主题的 $d_i$ 之和最多为 $4 \cdot 10^5$。

输出格式

输出在按照上述规则最优安排会议的情况下,所有会议中最长会议的最小可能长度。

样例

样例输入 1

3
10 0
10 0
10 0

样例输出 1

12

样例输入 2

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

样例输出 2

8

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.