logo AlgoBeat OnlineJudge
登录 注册

#216921. [NWERC 2018] Brexit Negotiations

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

As we all know, Brexit negotiations are on their way---but we still do not know whether they will actually finish in time.

The negotiations will take place topic-by-topic. To organise the negotiations in the most effective way, the topics will all be discussed and finalised in separate meetings, one meeting at a time.

This system exists partly because there are non-cyclic dependencies between some topics: for example, one cannot have a meaningful talk about tariffs before deciding upon the customs union. The EU can decide on any order in which to negotiate the topics, as long as the mentioned dependencies are respected and all topics are covered.

Each of the topics will be discussed at length using every available piece of data, including key results from past meetings. At the start of each meeting, the delegates will take one extra minute for each of the meetings that has already happened by that point, even unrelated ones, to recap the discussions and understand how their conclusions were reached. See the figure for an example.

Nobody likes long meetings. The EU would like you to help order the meetings in a way such that the longest meeting takes as little time as possible.

:::align{center}

:::

输入格式

The input consists of:

  • One line containing an integer (), the number of topics to be discussed. The topics are numbered from to .
  • lines, describing the negotiation topics. The th such line starts with two integers and (, ), the number of minutes needed to reach a conclusion on topic and the number of other specific topics that must be dealt with before topic can be discussed. The remainder of the line has distinct integers .

It is guaranteed that there are no cycles in the topic dependencies, and that the sum of over all topics is at most .

输出格式

Output the minimum possible length of the longest of all meetings, if meetings are arranged optimally according to the above rules.

样例

样例输入 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