luogu#P1673. [USACO05FEB] Part Acquisition S
[USACO05FEB] Part Acquisition S
Background
Description
The cows have been tasked with finding a new milking machine. To do so, they plan to pass through planets in sequence and trade on them. For convenience, the possible kinds of goods have been labeled from to . Since these planets are not very developed and there is no circulating currency, in each market you can only exchange one fixed item for another fixed item. The cows depart Earth carrying a premium feed and hope to obtain the required machine while minimizing the number of distinct item types used. The feed is labeled , and the required machine is labeled . If the task cannot be completed, output .
Output Format
Output the minimum number of distinct item types.
6 5
1 3
3 2
2 3
3 1
2 5
5 4
4
Hint
The cows need at least different labels: first exchange for , then for , and finally for .
, .
Translated by ChatGPT 5