luogu#P5096. [USACO04OPEN] Cave Cows 1

[USACO04OPEN] Cave Cows 1

Problem Description

Few people know that cows are actually quite fond of exploring caves.

Bessie is planning to visit her favorite cave, which has NN rooms (1N1001 \le N \le 100) numbered 1..N1..N and MM bidirectional corridors (1M10001 \le M \le 1000) connecting pairs of different rooms. Room 11 is the entrance to the cave. Two rooms are never directly connected by more than one corridor.

Always planning ahead, Bessie previously deposited a bale of hay in each of KK (1K141 \le K \le 14) different rooms so she will have food available during her expedition. Of course just like people, every time Bessie consumes a bale of hay, her "fatness" index increases by one unit.

When she enters the cave, her fatness index is 00 units. Every corridor in the cave has a certain width; Bessie can only fit through a corridor if her fatness index is no larger than that corridor's width.

Bessie wants to eat as much as possible during her trip into the cave but wants to make sure that she does not grow too fat and trap herself in the process (at the end of her trip she must exit the cave at room 11). Help her determine the maximum amount of hay she can eat.
Note that Bessie can decide to pass through a room containing a bale of hay without eating the hay, if she wishes.

Input Format

  • Line 11: Three space-separated integers: NN , MM, and KK.

  • Lines 2..K+12..K+1: Each of these lines contains the index (1..N1..N) of a room containing a bale of hay.

  • Lines K+2..K+M+1K+2..K+M+1: Each of these lines corresponds to a bidirectional corridor and contains three space-separated integers: indices of the two rooms connected by the corridor, and the corridor's integer width (1..1001..100).

Output Format

  • Line 11: A single integer giving the maximum number of bales of hay Bessie can eat and still successfully exit the cave.
6 7 5
1
2
3
4
5
1 2 3
3 6 2
6 2 10
2 4 1
5 1 1
4 5 1
1 6 1
4

Hint

OUTPUT DETAILS:

All corridors leaving the entrance room have width at most 33.
Thus, returning to that room Bessie must have eaten no more than 33 bales.
Combined with the bale in that room, 44 is the maximum number of bales that can be consumed.