编程介的小学生 2017-03-30 13:48 采纳率: 20.5%
浏览 748
已采纳

Green Dam Girl

Green Dam Girl (GDG) became bankrupt recently, and watashi picked her up to his dorm. Some ZJU ICPC team members would like to support her.

There are n team members who would like to support her. A member will give GDG q RMB (Renminbi, the currency of China) at the k-th night when GDG lives in his dorm continuously without any moving, where:

q = ai , if k = 1;
q = bi , if k = 2;
q = ci , if k ≥ 3.
GDG will get the money in the next morning.
Every afternoon, GDG can choose to move or not. But she has too much baggage to move all by herself. Luckily, she can turn to the member whose dorm she is currently in for help. Of course, it's not free -- GDG needs to bg (means treat) the member. The member will tell GDG whose dorm he can help her to move to and how much money she will cost correspondingly. Here are some notes:

If GDG don't get enough money to bg, she can't move to the dorm directly;
GDG can only ask the member whose dorm she is currently in for help;
GDG can move more than once. So, in order to move to some dorm, GDG may need to bg many times.
At the 1st night, GDG lives in watashi's dorm without any money. How much money can GDG possess before the d-th night?

Input

There are multiple cases. For each case, the first line contains two integers, n (1 ≤ n ≤ 100) and d (1 ≤ d ≤ 100). There are 2*n lines next. The (2*i+2)-th and (2*i+3)-th lines describe the information of the i-th (0 ≤ i < n) member, and watashi is always the 0-th member.

The (2*i+2)-th line contains 3 integers, ai, bi and ci (0 ≤ ai, bi, ci ≤ 10000). The (2*i+3)-th line begins with an integer mi (0 ≤ mi < n), followed by mi pairs of integers. The j-th (0 ≤ j < mi) pair of integers, numj (0 ≤ numj < n and numj ≠ i) and bgmj (0 < bgmj ≤ 10000), indicates that the i-th member can help GDG to move to the numj-th member's dorm as long as she cost bgmj RMB to bg him. It's guaranteed that each numj is different from others.

Output

For each case, output the maximum amount of money GDG can possess before the d-th night in a single line.

Sample Input

3 6
1 1 1
1 1 1
2 2 2
1 2 2
3 3 3
0
Sample Output

9

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-09 08:59
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端