Machine Shop
문제
Elise Isabella Oya works in the Cute Machine Shop. The shop sells many different machines. All of them can be bought from suppliers. Some of them can also be built in the shop from others; this may also be the case for the others in turn. For example, it may be possible to build the machine A from machines B and C, and the machine B in turn from machines D and E; thus, in this case, the machine A could also be built from machines C, D, and E.
Elise was asked for a price quote for a machine. To respond, she needs to know the lowest possible cost of obtaining the machine, whether by buying or by building it. The cost of labor in building a machine from others can be neglected.
입력
The first line contains space-separated integers and (), the number of different machines and the number of the machine Elise needs to obtain. The machines are numbered .
The following lines describe the machines, in the order of their numbers. First on each line is (), the cost of buying the machine . If the machine can only be obtained by buying it, the price is followed by a and there will be no more data on that line. Otherwise, the price is followed by (), the number of other machines needed to build the machine , and then by space-separated integers: the numbers of the other machines; these numbers will always be distinct. Additionally, it is known that no machine is a component of itself when it is built, neither directly nor indirectly (in graph-theoretical terms, we have a directed acyclic graph).
출력
Output exactly one integer: the minimal cost of obtaining the machine .
예제
예제 1
1 1 10 0
10
예제 2
5 1 50 3 2 3 4 30 2 4 5 20 2 4 5 5 1 5 10 0
35