8184: Bessie's Birthday Buffet 贝茜的生日自助餐

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

为了给奶牛贝茜庆生,约翰允许她在自己最肥沃的土地里自由的吃草。

该片土地中共有 N 块草地,编号 1∼N。

每块草地的青草质量都不相同。

如果贝茜吃了质量为 Q 的草,则会获得 Q 单位的能量。

每块草地都通过双向道路最多与十块其他草地连接。

贝茜沿一条道路从一块草地走到另一块草地需要花费能量 E。

贝茜可以选择在任意一块草地开吃,在积累了最大的能量后,她将停止。

不幸的是,贝茜是一个挑剔的牛。

一旦她吃了一定质量的草,她就再也不会吃质量等于或低于该质量的草了!

当她经过一片草地时,她可以选择不吃该草地的草。

事实上,她发现略过一些高质量的草,稍后折返享用十分有益。

请帮助贝茜计算她能积累的最大能量。

输入格式

第一行包含 N 和 E。

接下来 N 行,每行描述一块草地。首先包含两个整数 Q 和 D,分别表示草地质量以及与其相连的草地数量,然后包含 D 整数,表示与其相连的草地编号。

输出格式

输出贝茜可以积累的最大能量。

数据范围

1≤N≤1000,
1≤E,Q≤106,
1≤D≤10

输入样例:

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

输出样例:

7

样例解释

贝茜从第四块草地开始,从那里吃草获得 5 单位能量。

沿道路走到草地 5,损失 2 单位能量。

贝茜拒绝吃草地 5 的劣质草,直接消耗 2 单位能量前往草地 3。

在草地 3 吃草后,获得 6 单位能量。

此时,共积累 7 单位能量,这是能积累的最大能量。



For Bessie the cow’s birthday, Farmer John has given her free reign over one of his best fields to eat grass.

The field is covered in N patches of grass (1≤N≤1000), conveniently numbered 1…N, that each have a distinct quality value. If Bessie eats grass of quality Q, she gains Q units of energy. Each patch is connected to up to 10 neighboring patches via bi-directional paths, and it takes Bessie E units of energy to move between adjacent patches (1≤E≤1,000,000). Bessie can choose to start grazing in any patch she wishes, and she wants to stop grazing once she has accumulated a maximum amount of energy.

Unfortunately, Bessie is a picky bovine, and once she eats grass of a certain quality, she’ll never eat grass at or below that quality level again! She is still happy to walk through patches without eating their grass; in fact, she might find it beneficial to walk through a patch of high-quality grass without eating it, only to return later for a tasty snack.

Please help determine the maximum amount of energy Bessie can accumulate.

INPUT FORMAT (file buffet.in):

The first line of input contains N and E. Each of the remaining N lines describe a patch of grass. They contain two integers and D giving the quality of the patch (in the range 1…1,000,000) and its number of neighbors. The remaining D numbers on the line specify the neighbors.

OUTPUT FORMAT (file buffet.out):

Please output the maximum amount of energy Bessie can accumulate.

SAMPLE INPUT:

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

SAMPLE OUTPUT:

7

Bessie starts at patch 4 gaining 5 units of energy from the grass there. She then takes the path to patch 5 losing 2 units of energy during her travel. She refuses to eat the lower quality grass at patch 5 and travels to patch 3 again losing 2 units of energy. Finally she eats the grass at patch 3 gaining 6 units of energy for a total of 7 energy.

Note tha the sample case above is different from test case 1 when you submit.

[Problem credits: Austin Anderson and Brian Dean, 2015]

输入样例 复制


输出样例 复制