#P5096. Cow Cave Adventure
Cow Cave Adventure
Cow Cave Adventure
Few people know that cows love to explore caves. In a cave there are () chambers connected by () bidirectional corridors. Each pair of chambers is connected by at most one corridor. Additionally, there are () chambers that contain a bundle of hay. When Betsy the cow eats one bundle of hay, her weight index increases by .
Betsy starts her adventure at chamber with a weight index of . However, every corridor has a width threshold. If her current weight index exceeds the threshold of a corridor (i.e. if her weight index is greater than the threshold), she will get stuck. After exploring the cave, she must return to chamber .
Determine the maximum number of hay bundles Betsy can eat. Note that when passing through a chamber with hay, she does not have to eat the hay immediately.
inputFormat
The first line contains three integers , , and .
The next lines each contain three integers , , and , indicating that there is a bidirectional corridor between chambers and with a width threshold . (A corridor can be traversed if and only if the current weight index is less than or equal to its threshold.)
The following lines each contain one integer representing a chamber that contains a bundle of hay. It is guaranteed that these chambers are distinct.
outputFormat
Output a single integer representing the maximum number of hay bundles Betsy can eat while starting and ending at chamber .
sample
4 4 2
1 2 3
2 3 1
3 4 1
4 1 1
2
3
1