luogu#P5096. [USACO04OPEN] Cave Cows 1
[USACO04OPEN] Cave Cows 1
Problem Description
Few people know that cows actually really like exploring caves.
There are ( ) chambers in the cave, connected by ( ) bidirectional passages. Between any pair of chambers, there is at most one bidirectional passage. There are ( ) chambers, each containing one bale of hay. Every time a cow eats one bale of hay, her weight index increases by .
The greedy Bessie wants to explore the cave and hopes to eat as much hay as possible, but each passage has a width threshold: if her weight index exceeds the corresponding threshold, Bessie will get stuck.
She starts from chamber with weight index . After wandering around in the cave, she must return to chamber .
What is the maximum number of hay bales she can eat? Note that when Bessie passes through a chamber, she does not have to eat the hay in it.
Input Format
The first line contains .
The next lines each contain one integer, indicating a chamber that contains one bale of hay. Then the next lines each contain three integers, indicating the two endpoints of a bidirectional passage and its width threshold.
Output Format
The maximum number of hay bales that can be eaten.
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
Translated by ChatGPT 5