문제
The cows are heading back to the barn at the end of a long day, feeling both tired and hungry.
The farm consists of
Being hungry, the cows are interested in potentially stopping for food on their way home. Conveniently,
Problem credits: Dhruv Rohatgi
입력
The first line contains three space-separated integers
The next
출력
The output should consist of
예제
4 5 1
1 4 10
2 1 20
4 2 3
2 3 5
4 3 2
2 7
1
1
1
In this example, the cow in pasture 3 should stop for a meal, since her route would only increase by 6 (from 2 to 8), and this increase is at most the yumminess 7 of the haybale. The cow in pasture 2 should obviously eat the hay in pasture 2, since this causes no change in her optimal route. The cow in pasture 1 is an interesting case, as it may first appear that her optimal route (length 10) would increase too much to justify stopping for the hay. However, she actually does have a route that makes stopping at the hay beneficial: move to pasture 4, then to pasture 2 (eating the hay), then back to pasture 4.